0

Using hierarchical datas, I would like to allow users to be able to select an item to view its corresponding subitems.

Example :

Item A
-> SubItem1
-> SubItem2
-> SubItem3
Item B
-> SubItem4
-> SubItem5

PieChart shows Item A and Item B. If Item1 is clicked, PieChart is reloaded and shows SubItem1, SubItem2 and SubItem3. If Item2 is clicked, PieChart is reloaded and shows SubItem4 and SubItem5.

How do I load my datasource ? Should I create a serie for Item A (ItemA, SubItem1, SubItem2, SubItem3) and one for Item B, or should I create one for first level (Item A, Item B) and each subitem group?

Is there a way to select which serie is currently displayed?

Thank you very much :)

1 Answers1

0

I think there are multiple ways you could do this, but here is quite a neat way.

You could create a 'smart' data-source with methods that alter the data it will offer up to the chart. Then you could call these methods in response to chart interaction (within your chart's delegate) and reload your chart. Your data-source's interface could look something like this:

public interface SmartDataSource
{
   void SetToShowDataForItem(Item level);
}

You could implement the method OnToggledSelection method and when a user taps on a slice you could get the Item corresponding to the slice they tapped on, call 'SetToShowDataForItem', and reload your chart like so:

protected override void OnToggledSelection (ShinobiChart chart, SChartRadialDataPoint dataPoint, SChartRadialSeries series, PointF pixelPoint)
{
    Item item = myItems[dataPoint.index];
    SmartDataSource sDataSource = chart.DataSource as SmartDataSource;

    if (sDataSource != NULL) {
        sDataSource.SetToShowDataForItem(item); 
        chart.ReloadData();
        chart.RedrawChart();
    }
}

The demos packaged with the framework might help you too. If you look at the native iOS pie chart demo, they do something similar to what you are trying to do, although they have a secondary pie chart.

Good luck!

jaker
  • 7,730
  • 1
  • 20
  • 22