|
Pie chart custom format for legend and sector labels |
Posted by Charlie Brown on Sep-18-2014 16:25 |
|
Hi Peter,
Thanks for your reply.
However the legendBox.setText sets for all the items in my legend box, with the last entry
in my array of sectorLabel and longLabels.
I do it as follows:
LegendBox legend = c.getLegend();
for (int i = 0; i < longLabels.length; i++) {
legend.setText("{"+sectorLabel[i]+"}"+"({"+longLabels[i]+"})");
}
Regards
Charlie |
Re: Pie chart custom format for legend and sector labels |
Posted by Peter Kwan on Sep-19-2014 00:09 |
|
Hi Charlie,
The code should be:
c.setData(myData, sectorLabel);
c.addExtraField(longLabels);
c.getLegend().setText("{label} ({field0})");
There is no need to use a loop. When ChartDirector sees the line, it will replace the {label}
with the actual sector label for that sector, and the {field0} with the extra field for that
sector. It should be entered exactly as "{label} ({field0})".
Hope this can help.
Regards
Peter Kwan |
Re: Pie chart custom format for legend and sector labels |
Posted by Charlie Brown on Sep-19-2014 19:17 |
|
Hi Peter,
Setting of legend works like a charm. Thank you.
However my sector labels are always showing the same value (last entry of myLabels)
This is how I do:
double myData[] = {17.5, 14.370000000000001, 14.360999999999999,
13.478000000000002, 12.936, 14.056999999999999, 10.062, 12.0};
String myLabels[] = {"14-07-09 23:07", "14-08-09 23:07", "14-07-10 23:07", "14-07-12
23:07", "14-08-13 23:08", "14-08-14 23:08", "14-09-14 23:08", "14-10-14 23:08"}
String myLongLabels ={"long label1", "long label2", "long label3", "long label4", "long
label5", "long label6", "long label7", "long label8"}
PieChart c = new PieChart(.......);
c.setData(myData, myLabels);
c.addExtraField(myLongLabels);
LegendBox b = c.addLegend(........);
b.setText("{label}({field0})");
Now all the legend texts are appearing correctly. But the all the sectors are having the last
entry of myLabels 14-10-14 23:08. |
Re: Pie chart custom format for legend and sector labels |
Posted by Charlie Brown on Sep-19-2014 20:03 |
|
I found the solution to my problem.
I had to set the labelFormat as follows:
double myData[] = {17.5, 14.370000000000001, 14.360999999999999,
13.478000000000002, 12.936, 14.056999999999999, 10.062, 12.0};
String myLabels[] = {"14-07-09 23:07", "14-08-09 23:07", "14-07-10 23:07", "14-07-12
23:07", "14-08-13 23:08", "14-08-14 23:08", "14-09-14 23:08", "14-10-14 23:08"}
String myLongLabels ={"long label1", "long label2", "long label3", "long label4", "long
label5", "long label6", "long label7", "long label8"}
PieChart c = new PieChart(.......);
#write down exactly "{label}" in the following statement.
c.setLabelFormat("{label}");
c.setData(myData, myLabels);
c.addExtraField(myLongLabels);
LegendBox b = c.addLegend(........);
b.setText("{label}({field0})"); |
|