Display a horizontal bar graph with ordered data in iOS (objective c)


#1

I’m putting into practice the graphic SChartBarSeries in iOS , the question is how can I assign a defined order , data to be displayed on the graph.

The data are: Modified , Exercised , Committed ,accrued,Pre-committed,Approved and paid , I need to show them in the order: paid,exercised,accrued,committed, Pre-committed , Modified , Approved

could give me an example , thanks for the help .


#2

Hi Aleck,

I presume you’re referring to the order that the columns appear?

Are you using NSDictionary to store your data? As this would not guarantee your collection remains in the order you initialised it as. If this the case you could potentially either look at using an ordered dictionary or alternatively creating a class to store the key and value of your key value pair and storing your data in an array as this maintains order. This is because a category axis displays data points in the order that they are supplied to the chart.

If you are still having trouble to achieve this, please include a code sample in your next post to allow me to see exactly what it is you’re trying to achieve.

  • Matt

#3

Thanks , If I refer to the order as the columns are appearing , if I use a NSDictionary to create it declared two NSMutableArray one I assign values ​​and other fields below will show you some of the code , what I want is to show me the order as found in the NSMutableArray , which have not succeeded , do not understand that does not respect me the orde, could give me an example , thank you for your attention and your help provided.

  • ( Void ) {construirgraficaBarras    

    NSMutableArray * llaves, * Valores;

    llaves = [[NSMutableArray alloc] init ];

    Valores = [[NSMutableArray   alloc] init ];

    [Auto leyenda];

    DADataTableRow * rowMomentos = [[DADataTableRow alloc] init ];

    

    párrafo ( int i = 0 ; i < memMomentosC . rowCount ; i ++) {

        rowMomentos = [memMomentosC . Filas objectAtIndex : i];

        SI ([rowMomentos valueForKeyPath : @ “Valor”] =! nil ) {

            SI ([rowMomentos valueForKeyPath : @ “porcentaje”] == nil ) { 

                [rowMomentos setValue : @ “0.00” forKeyPath : @ “porcentaje”]; 

                [MemMomentos postAll];  +

            }

            NSString * presupuesto = [rowMomentos valueForKeyPath : @ “Valor”]; +

            NSNumber * num = [DMFunciones convertStringToNumber : presupuesto formato : @ “Decimales” NumDecimales : 0];

            SI (num == nil   || num <= 0 ) { 

                num = [NSNumber numberWithDouble : 0.00]; 

            }            

            NSString * des = [rowMomentos valueForKeyPath : @ “Descripcion”];

            SI ([des isEqualToString : @ “Estimado”] || [des isEqualToString : @ “Modificado”] || [des isEqualToString : @ “Aprobado”]) {

                [Valores InsertObject : num atIndex : i];

                [Teclas InsertObject : [@ “” stringByAppendingFormat : @ “% i% @% @% @% @% @ (% @)” , i, [rowMomentos valueForKeyPath : @ “Valor”], @ “” , des, @ " " , [[rowMomentos valueForKeyPath : @" porcentaje “] stringByAppendingString : @”% " ], mesAnualAux ] atIndex : i];

            } Demás {

                [Valores InsertObject : num atIndex : i];

                [Teclas InsertObject : [@ “” stringByAppendingFormat : @ “% i% @% @% @% @% @” , i, [rowMomentos valueForKeyPath : @ “Valor”], @ “” , des, @ “” , [[rowMomentos valueForKeyPath : @ “porcentaje”] stringByAppendingString : @ “%” ]] atIndex : i];

           }

        }

    }

    [Gráfico removeFromSuperview];

    Carta = nil ;

    Datos = nil ;

    Datos = [NSDictionary dictionaryWithObjects : Valores forKeys : Teclas];


#4

Hello Aleck,

As mentioned above this is because the NSDictionary does not maintain order. This means even if you declared a dictionary with the below dataset:

A : 1, B : 2, C : 3

You are not guaranteed that they will come back in that order when you use the dictionary as a datasource. Instead you could use the NSMutableArray’s directly as they guarantee the order of the values placed inside of them. 

Kind regards,

Matt