1
votes

I used core plot and it's working very well but ..there are problem now, i have to draw n number Bars in single plot space dynamically...it may be 2 or 3 or 5 or non.

i am able to create multiple instance of the Bar ..but where i set the identifier dynamically and how handle every bar draw calculation in side delegate. My Code snippet is below.

-(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:(NSUInteger)index
{
if([plot.identifier isEqual:kBarIdentifier1])
 {
   //....getting data from array and return .
 }
}
1

1 Answers

0
votes

Your question is still at a higher level but i will try to answer as per my understanding:

  • where i set the identifier dynamically : You can have some constants strings which you can use for setting identifiers. If you want to make it completely dynamic take a counter and use it's value to set as identifier like:

    plot.identifier = [NSString stringWithFormat:@"%d",counter];
    

    Create the plot inside a loop as per dynamic req. and just after creating instance set the identifier as per counter.

  • how handle every bar draw calculation in side delegate : This is not so clear what you want to know. This method is called according to count you will pass in delegate method:

      -(NSUInteger)numberOfRecordsForPlot:(CPTPlot *)plotnumberOfRecords {
    return someCount;
    }
    

    The delegate method "numberForPlot" will be called for each plot as per someCount. Identify the plot & take value from some array and return the value.

//edit:

  -(NSNumber *)numberForPlot:(CPTPlot *)plot field:(NSUInteger)fieldEnum recordIndex:     (NSUInteger)index
   {
    if (fieldEnum == CPTBarPlotFieldBarTip) {
     //compare identifiers from a list of identifier maintained
     if ([plot.identifier isEqual:identifier1]) {
        return value;//get value from some array having values for plot identifier1
    }        
    ///and so on for all identifiers

    } 

    if(fieldEnum == CPTScatterPlot)//not sure on enum please check 
     {
         //handle similar to above one
     }
  }