Hi,
There are two questions about customization of IGPieChartView. Thanks in advance.
1. I want to show NO label in my chart, but labels in legend. I can switch labels on/off by setting _infraPieChart.labelsPosition = IGLabelsPositionNone, however, this property will impact labels in chart and legend at same time. Is it possible to just make label visible in Legend ?
2. I want to show Labels in legend in some certain format, like 'LabelName : Value'. Found that there is a method called 'labelWithItem' under IGPieChartViewDelegate, but seems it never gets hit. The other two 'taoWithItem' and 'viewForTooltipWithItem' are working properly. How can I customize labels in legend ?
Regards,
Allen.
Hi Allen,
After testing what you mentioned in #1, I see there is a bug present that affects the connection between labelsPosition property and the legend. In addition, pieChartView:labelWithItem: does appear to be suffering from issues too. I'll be going over these issues with my colleague to make sure we get these fixed as soon as possible and get a service release out.
In the meantime, if you want to customize the labels shown on the pie chart or legend it's possible to create a custom data object that contains a value and label property as shown below.
-(NSMutableArray*) createSimpleData:(int)recordCount{ NSMutableArray * retValue = [[NSMutableArray alloc]init ]; for (int i = 0 ; i < recordCount ; i++) { SimpleData *data = [[SimpleData alloc]initWithValue:i andLabel:[NSString stringWithFormat:@"Slice %d", i]]; [retValue addObject:data]; } return retValue;}
Once you populate the mutable array with your custom data object, you initialize the data source helper.
IGPieChartViewDataSourceHelper _source = [[IGPieChartViewDataSourceHelper alloc] initWithData:_data valuePath:@"value" labelPath:@"label"];
I'm sorry for the issues you've experience and hope my suggestions help.
Hi Torrey,Thanks for your explanation and suggestion. Yes, what you suggest would work for my scenario, as long as we get No.1 fixed so that I can show customized labels in Legend and make labels invisible from chart. Looking forward to next service release. Thanks.Regards,Allen.
We've fixed the issues you were experiencing with the pie chart. LabelsPosition property will only affect labels in the pie slices and the delegate method will be called as expected. We have to do some testing and all this will be available in the upcoming service release. It's tentatively scheduled for friday 8/9.
Regarding the delegate method, the signature will change to provide the actual label string along with the slice info. It's going to be
-(NSString*)pieChartView:(IGPieChartView*)pieChartView label:(NSString*)label item:(IGPieSliceInfo*)item;
This method will only change the label inside the slice and will not affect the label displayed in the legend. It's more suitable for providing alternate description for the slices or special formatting. It may not be a good idea to have all that extra text in the legend as well to avoid unnecessary clutter. If you need to use formatting or change the label in any way that affects both slices and the legend, you can use the method suggested by Torrey or you can have your view or view controller implement IGPieChartViewDataSource protocol. You would have to implement 2 methods, where you basically tell the chart how many items you have and create data points with values and any kind of labels you would like. Here's a quick example of how this might look:
-(int)numberOfPointsInPieChartView:(IGPieChartView *)pieChartView{ //let's assume _data is an array of NSNumbers. return _data.count;}
-(IGDataPoint *)pieChartView:(IGPieChartView *)pieChartView pointAtIndex:(int)index{ double value = [(NSNumber*)_data[index] doubleValue]; //any text set here will be displayed in the slices and the legend. NSString *label = [NSString stringWithFormat:@"Item %d", index]; return [[IGCategoryPoint alloc]initWithValue:value andLabel:label];}
We have situation where we want to show the % of the pie slice as of the total pie in the chart label.
Hooking into -(NSString*)pieChartView:(IGPieChartView*)pieChartView label:(NSString*)label item:(IGPieSliceInfo*)item; only works until the pie is exploded.
When the pie explodes the legend label now gets the modified string we created in the -(NSString*)pieChartView:(IGPieChartView*)pieChartView label:(NSString*)label item:(IGPieSliceInfo*)item; method.
Is it a way we can have a different label in the pie and legend when pie chart is exploded?
How can i get IGPieSliceInfo index value in Xamarin c#.
For example I have a pie chart with two slice. One is Ontime and Lateness. I didn't show label on the IGpiechartview. So how can i get the particular slice is click. I am using following code. in this override method i want to get information about clicked slice.
If user click on OnTime slice then i want to get that OnTime slice information. In the following code i am getting value and label but i didn't show the label on slice. There is a way to Hidden the label value on slice.
Thanks,
seshu P.
Cycle through the .dataPoints collection off the chart and find the object
public override void ItemTapped (IGPieChartView pieChartView, IGPieSliceInfo item, System.Drawing.PointF point) { IGCategoryPoint dataPoint = (IGCategoryPoint)item.Item; for (int i = 0; i < pieChartView.DataPoints.Count; i++) { IGCategoryPoint tempObject = pieChartView.DataPoints.GetItem<IGCategoryPoint>(i); if (dataPoint == tempObject) { // now i is your index; int xx = 0; xx++; } } }
My pie chart always contains to slides on is ontime and another one is latetime. When ever user click on ontime slice then i want to get that slice index value. Based on that index value i want show data. How can i get the slice index value when ever user tapped on slice. I want code snippet in C#.net
public override void ItemTapped(IGPieChartView pieChartView, IGPieSliceInfo item, System.Drawing.PointF point) {
}
using this method possible to get slice index.
That would translate to the GetPointAt method off the datasource helper.
It would look something like this:
public override IGDataPoint GetPointAt (IGPieChartView pieChartView, int index) { double myValue = ((NSNumber)_data [index]).DoubleValue; NSString newString = "someNewString"; return new IGCategoryPoint (myValue, newString); }
I want this one in c#