ChartDirector Support Forum Home   Search
Single XYChart Still display sectors that have 0 value
Posted by Donavon Lerman on Nov-27-2018 08:43
Is there a way to display the sections that have a 0 value?

I need to display the color and a value of 0 on hover and {value}.

~Donavon

Re: Single XYChart Still display sectors that have 0 value
Posted by Peter Kwan on Nov-27-2018 21:55
Hi Donavon,

I am not too sure the type of "sections" or "sectors" you are referring to.

In your subject, you mentioned about "XYChat". Is it a bar chart or a line chart or other kinds of chart? Is the "section" you are referring to a "bar segment" or a "line segment" or something else?

ChartDirector draws zero values in many case. A line segment at y = 0 will be drawn as a line segment at y = 0. However, it may overlap with the axis also at y = 0, so you may or may not see it depending on how your chart is configured.

In some type of chart, a visible segment is not logical. For example, if we have a stacked bar chart with 10 stacks, and all of them is 0. If you make them visible, it must have at least 1 pixel, and then stacked bar will end up 10 pixels high, which may be a significant value on the axis. But the entire bar should be 0 since every segment is 0. This can be very mis-leading.

So exactly how zero can be displayed depends very much on the chart type and the data organization (such as if the data are stacked, etc).

Regards
Peter Kwan

Re: Single XYChart display "bar segment" that have 0 value OR keep coloring sequence through 0 values.
Posted by Donavon Lerman on Nov-28-2018 02:50
Attachments:
Thank You Peter for the response.

So it would be "bar segment".  Attached are 3 pictures as an example.

1st has even distribution of numbers:  25,25,25,25,25,25,25,25
2nd has uneven distribution of numbers: 4,5,16,8,11,6,2,0
3rd has uneven distribution of number but with several 0 values: 0,0,1,0,2,1,1,0

For the 3rd picture this throws things off.  If I display all charts on the same page the coloring for the "bar segments" do not match even though they have the same amount of data elements.  "Age 2" should be blue or what ever the auto color for the 3rd "bar segments" is and "Age 4" should be Pink, etc, etc...

In the 3rd picture, either..
- How do I display a very small segment just so the color is seen
OR
- How do I get the coloring to be in the same sequence as the others even with 0.

Thank You,
~Donavon

Re: Single XYChart display "bar segment" that have 0 value OR keep coloring sequence through 0 values.
Posted by Peter Kwan on Nov-28-2018 18:01
Attachments:
Hi Donavon,

ChartDirector should keep the color even if the data value is 0. For the 3rd chart, are you sure you are passing {0, 0, 1, 0, 2, 1, 1, 0} to ChartDirector, and not just {1, 2, 1, 1}?

For example, if your data comes from an SQL query, using "COUNT" and "GROUP BY" statement to count the frequency of each age group, then the SQL will only return 4 rows for {1, 2, 1, 1}. If you just pass these 4 numbers to ChartDirector, but not the 0 values, then it will result in your 3rd chart.

I am not sure which programming language you are using. I will use C# to create an example that you can test:

double[] data = {0, 0, 1, 0, 2, 1, 1, 0};
string[] labels = {"Age 0", "Age 1", "Age 2", "Age 3", "Age 4", "Age 5", "Age 6", "Age 7" };

XYChart c = new XYChart(500, 150);
c.setPlotArea(50, 20, 400, 100, -1, -1, Chart.Transparent, Chart.Transparent);
c.xAxis().setColors(Chart.Transparent, Chart.Transparent);
c.yAxis().setColors(Chart.Transparent, Chart.Transparent);
c.swapXY();

BarLayer layer = c.addBarLayer2(Chart.Percentage);
for (int i = 0; i < data.Length; ++i)
layer.addDataSet(new double[] { data[i] }, -1, labels[i]);
layer.setDataLabelFormat("{dataSetName}: {value}");
layer.setDataLabelStyle("Arial", 12).setAlignment(Chart.Center);

viewer.Chart = c;

The above should confirm that 0 will use up a color in the sequence.

Regards
Peter Kwan