How multiple charts synchronized


#1

Anyone has an example on how to move a graphic from another. The 2 graphic are same xValues and i need moved together from one of them.

Please…  :fearful:


#2

Hi Pamela,

I will post below a code snippet that should allow you to synchronise the ranges of any number of charts. Each of the charts will have to have the same delegate and in this delegate you should implement a NSArray ivar, in the example code below I have called this _managedCharts. This array basically keeps track of all the charts we want to update. In your delegate, implement the following.

// Whenever a chart is zooming we need to update all other managed charts with the same axis ranges as this one. 
-(void)sChartIsZooming:(ShinobiChart *)chart withChartMovementInformation:(const SChartMovementInformation *)information { 
  [self updateChartsRangesFromChart:chart]; 
}

// Whenever a chart is panning we need to update all other managed charts with the same axis ranges as this one. 
- (void)sChartIsPanning:(ShinobiChart *)chart withChartMovementInformation:(const SChartMovementInformation *)information { 
  [self updateChartsRangesFromChart:chart]; 
}

Every time any of our charts pans or zooms it will call the updateChartsRangesFromChart: method. Here we need to update every charts range, except the one that just moved. Here is my implementation of that method:

// This method updates all charts in the _managedCharts array with the chart’s axis ranges passed in as the parameter. 
- (void) updateChartsRangesFromChart:(ShinobiChart *)chart { 
  
  // Loop through our managed charts. 
  for (ShinobiChart *charToUpdate in _managedCharts) { 
  
    // Update all charts apart from the chart we are updating from. 
    if (charToUpdate != chart) { 
  
      // Get the X and Y axis ranges off the chart we are updating our axex from. 
      SChartRange *zoomedXRange = chart.xAxis.axisRange; 
      SChartRange *zoomedYRange = chart.yAxis.axisRange; 
  
      // Update the X and Y ranges of this chart. 
      [charToUpdate.xAxis setRangeWithMinimum:zoomedXRange.minimum andMaximum:zoomedXRange.maximum]; 
      [charToUpdate.yAxis setRangeWithMinimum:zoomedYRange.minimum andMaximum:zoomedYRange.maximum]; 
  
      // Redraw this chart. 
      [charToUpdate redrawChart]; 
    } 
  } 
}

Now if you pan or zoom any of the charts you added to your _managedCharts array you should see the same panning and zooming behaviour replicated in the other charts. I hope this helped :grin:!

Jan