I have the following weird problem when using Charts.
I have six DataSeries named A, B, C, D, E, and F - each with a single DataSeriesItem. Five of the six DataSeriesItem were created with a category X and one of them with category Y. Something like this:
A = new DataSeries(“A”);
A.add(new DataSeriesItem(“X”, 6);
B = new DataSeries(“B”);
B.add(new DataSeriesItem(“X”, 5);
C = new DataSeries(“C”);
C.add(new DataSeriesItem(“Y”, 4);
D = new DataSeries(“D”);
D.add(new DataSeriesItem(“X”, 3);
E = new DataSeries(“E”);
E.add(new DataSeriesItem(“X”, 2);
F = new DataSeries(“F”);
F.add(new DataSeriesItem(“X”, 1);
ArrayList list = new ArrayList();
list.add(A); list.add(B); list.add(C); list.add(D); list.add(E); list.add(F);
Configuration.setSeries(list);
Then I create an X-Axis with two categories - “X” and “Y” and add it to the Configuration:
XAxis xAxis = new XAxis();
xAxis.setCategories(new String {“X”, “Y”});
Configuration.addxAxis(xAxis);
But when the chart gets displayed, only category “X” shows up on the X-Axis and all 6 series’ data items get shown over that one category, including C’s data item - which is actually of category “Y”. Can anyone tell me what I"m doing wrong - or if this is a bug?
As an additional data point: when I add an additional data item for series C that is of category “X”, everything works as expected:
C.add(new DataSeriesItem(“X”, 12);
It seems that the “Category” on the DataSeriesItem is totally ignored and, instead, positional logic is used to determine which category a given DataSeriesItem goes into - i.e. the 1st element of each series always goes into the 1st category, the 2nd element of each series into the 2nd category, etc. If that’s the case, it begs the question "Why have category names for DataSeriesItems?
Matti, Gerhard,
The suggestion of using “chart.getConfiguration().getxAxis().setType(AxisType.CATEGORY);” instead of using setCategories() didn’t work - same result. The chart ends up just showing one label - “X”. So this is a bug - I filed it at http://dev.vaadin.com/ticket/13050