Hi Syam, Great job, awsome charts ;)I have some code like below.<

Hi Syam, Great job, awsome charts ;)

I have some code like below.

Question, how to superimpose one bar on second bar,

mean I would like to have value y1 behind value y2.

All is working when I have Data type in x variable, but when I am changing

variable x to CategoryData then I have chart from y1 on top of chart y2, but

I need y1 value behind y2.

Can You help me?


CategoryData x = new CategoryData("Banana","Mango","Apple","Juice","Orange");

Data y1 = new Data(5,9,6,7,8);

Data y2 = new Data(4,8,7,8,9);


SOChart soChart = new SOChart();


soChart.setSize("1200px", "500px");


BarChart barChart1 = new BarChart(x,y1); barChart1.setName("Capacity"); barChart1.setStackName("ONE");


BarChart barChart2 = new BarChart(x, y2); barChart2.setName("Used Capacity"); barChart2.setStackName("ONE");

barChart2.setColors(new Color("#25B15F"));


XAxis xAxis = new XAxis(DataType.CATEGORY);

YAxis yAxis = new YAxis(DataType.NUMBER);


RectangularCoordinate rectangularCoordinate = new RectangularCoordinate(xAxis,yAxis);


barChart1.plotOn(rectangularCoordinate); barChart2.plotOn(rectangularCoordinate);


soChart.add(rectangularCoordinate);

Hi,

If you set "stack name", the bars will be stacked. Here, you want 2 independent bar charts one plotted on top of the other one. So, your code should look as follows:

CategoryData x = new CategoryData("Banana","Mango","Apple","Juice","Orange");
Data y1 = new Data(5,9,6,7,8);
Data y2 = new Data(4,8,7,8,9);
SOChart soChart = new SOChart();
soChart.setSize("1200px", "500px");

BarChart barChart1 = new BarChart(x, y1);
barChart1.setName(“Capacity”);
//barChart1.setStackName(“ONE”);

BarChart barChart2 = new BarChart(x, y2);
barChart2.setName(“Used Capacity”);
//barChart2.setStackName(“ONE”);
barChart2.setColors(new Color(“#25B15F”));

XAxis xAxis1 = new XAxis(DataType.CATEGORY);
XAxis xAxis2 = new XAxis(DataType.CATEGORY);
YAxis yAxis = new YAxis(DataType.NUMBER);

RectangularCoordinate rectangularCoordinate = new RectangularCoordinate(xAxis1, xAxis2, yAxis);

barChart1.plotOn(rectangularCoordinate, xAxis1, yAxis);
barChart2.plotOn(rectangularCoordinate, xAxis2, yAxis);
xAxis2.hide();

soChart.add(rectangularCoordinate);
setComponent(soChart);

Hi

Thanks a lot, great job!

I have another question, how to solve issue when I have long labels name on X axis then they not showing. I need to have all labels visable, long and short.

You can rotate the labels to fit in. Also, provide enough space at the bottom.

xAxis1.getLabels(true).setRotation(-45);
rectangularCoordinate.getPosition(true).setBottom(Size.percentage(30));

Thank You Syam, great job !