ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Systematically getting one additional "0" slice at pie chart
Posted by Guillermo Ganem on May-18-2011 02:09
Hi Peter,

I have an application that compares two sets of data, each of which can have up to 50 values.  The application allows the user to pick elements from each data set, and then loads the selected values into the pie chart's data array.  Once the data is loaded, the pie chart is displayed with exploded values comparing Group A vs Group B.

Although there is no practical application for selecting the 100 values (50 each side), theoretically it can be done, so I am initialising the data array with 100 "0" values just in case:
double chart_data [] = {0, 0, 0, .... 0};
char chart_labels [] = {"", "", "", ....""};

The application works fine in filling the data array with the corresponding values (usually a max of 10, typically 4-7 slices), and showing the pie chart, except for a small detail:  there is systematically one additional slice "graphed" by the pie-chart, with value 0.  I hadn't noticed it until I integrated labels, so I found out I am having systematically "the last" slice with 0 value.

At first I tried to find a variable that provides the # of slices to the chart, but I realised that the structure receives the whole data array and somehow determines the number of slices by itself.  I then tried to initialise the data array with negative values, but I still get the "-1" values graphed and at the labels (no label shown, being NULL, but "0, 0%" is systematically displayed).

How can I tell the pie chart the actual number of slices to take into account is n-1?

A couple of additional questions, about small details:
1. How can I indicate to the setLabelFormat function to display real numbers with commas and, when the case applies, with or without a certain number of decimals?

2. Can I pass any command to show the cumulated values of exploded groups?  I would like to show something like the following:

Title:  "Operational benchmark - Number of branches"
Group1:  "Bank1+Bank8+Bank34" (or "Group1", fixed name) = 3,820 branches (total).
Group2: "Bank36+Bank48" (or "Group2", fixed name) = 5,621 branches (total).
And then show the pie chart, with the 3 slices from Group 1 + 2 slices of Group2.
Note:  I have the subtotals for each group at my program.  If the Exploded values functions doesn't work, I guess I could put together the string and strcat to the Chart's Title, but I don't like that solution very much.

Below the code that I am using for preparing the info to send the pie chart for display, in case it's useful (basically the same than examples, adapted to my chart).

Thanks in advance.  Regards, GGC


        strcat (chartTitle, "\\n"); strcat (chartTitle, chartSubtitle);
        pie->addTitle(chartTitle, "timesbi.ttf", 8)->setBackground(0xaaaaff);
        // pie->addTitle(chartSubtitle, "timesbi.ttf", 8)->setBackground(0xaaaaff);
        // Set the center of the pie at (180, 140) and the radius to 100 pixels
        pie->setPieSize(180, 175, 75);
        // Set the pie data and the pie labels
        pie->setData(DoubleArray(chart_data, sizeof(chart_data)/sizeof(chart_data[0])), StringArray(chart_labels,
            (sizeof(chart_labels)-1)/sizeof(chart_labels[0])));
        // Draw the pie in 3D with variable 3D pie_depths
        pie->set3D(DoubleArray(pie_depths, sizeof(pie_depths)/sizeof(pie_depths[0])));

        // Set the start angle to 225 degrees may improve layout when the pie_depths of the
        // sector are sorted in descending order, because it ensures the tallest sector
        // is at the back.
        pie->setStartAngle(180);

        pie->setLabelFormat(
        "<*block,halign=center,width=110*>{label}\\n<*font=arial.ttf,size=8*> "
        "{value}M ({percent}%)<*/*>");

        // Explode all sectors 10 pixels from the center
        pie->setExplodeGroup(0,selBankSlices-1, 10);

  Re: Systematically getting one additional "0" slice at pie chart
Posted by Peter Kwan on May-18-2011 19:14
Hi Guillermo,

You can pass the array length to ChartDirector in DoubleArray. For example, instead of using:

DoubleArray(chart_data, sizeof(chart_data)/sizeof(chart_data[0]))

please use:

DoubleArray(chart_data, no_of_values)

The same applies to the StringArray.

You may use setLabelFormat to format the labels to display real numbers with commas and with a certain number of decimals. (In the documentation for PieChart.setLabelFormat, there is a link to "Parameter Substitution and Formatting", which explains the detail syntax.)

I am not sure what exactly is "display real numbers with commas" refer to. I assume you mean the commas are used as decimal separators (as opposed to thousand separators). In this case, the code is like:

//2 decimal place, no thousand separator, use comma as decimal separator
pie->setLabelFormat(
        "<*block,halign=center,width=110*>{label}\\n<*font=arial.ttf,size=8*> "
        "{value|2~,}M ({percent|2~,}%)<*/*>");

For showing the cumulated values of exploded groups, instead of using the chart title, you may use BaseChart.addText to add the text to any arbitrary position in the chart. For example, you may put two lines under the pie to describe the cummulated values. If you like, you can even compute the position of the exploded group, and put the labels next to the groups.

Hope this can help.

Regards
Peter Kwan

  Re: Systematically getting one additional "0" slice at pie chart
Posted by Guillermo Ganem on May-20-2011 01:20
The pie charts are now optimised in their final form.  I am very impressed about the intelligent handling of the labels, which do not overlap even when there are a lot of sectors.  Thanks for the support!