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

Message ListMessage List     Post MessagePost Message

  Stacked Bar Chart with "variable" numbers of stacks
Posted by MarkZB on Jun-11-2018 14:34
Attachments:
Is this possible? I'm not sure how to change the data...

// The data for the bar chart
double[] data0 = {100, 115, 165, 107, 67};
double[] data1 = {85, 106, 129, 161, 123};
double[] data2 = {67, 87, 86, 167, 157};
VariableStacks.png

  Re: Stacked Bar Chart with "variable" numbers of stacks
Posted by Peter Kwan on Jun-12-2018 04:22
Hi MarkZB,

If the overall coloring scheme of the stack bars follow a fixed sequence, you can use one dataset per stack. It is possible that some bars would not have some stacks by setting the values of those segments to 0 for that bar.

If the colors of the bars are entire independent, you may consider to just use put each bar in a separate bar layer. In this way, each bar layer only has one bar, and you can use one dataset per segment. For a bar, if your code put the segment values and their colors in two arrays, you can use something like:

BarLayer layer = c.addBarLayer2(Chart.Stack);
layer.setXData(new double[] {0});  // the x-position of the bar
for (int i = 0; i < data.Length; ++i)
   layer.addDataSet(new double[] { data[i] }, color[i]);  // one dataset per segment

The above is for a stacked bar at x = 0 (the first label position). You can use the same method to put a bar at x = 1, 2, 3, ... with different data and color arrays.

Hope this can help.

Regards
Peter Kwan