I have a problem in which I'm trying to display a few types of data in a single chart and it's not going well.
First of all, I have one series of data that is supposed to be displayed as a line chart, and then I have to add some bar charts. The number of bars depends on other conditions but it will be a number between 3 and 5. Each bar series is supposed to be created as a new IBarSeries because I have to check if each of them is bigger than the line chart value and change its color if true.
The main function that creates char data looks like that
private void setChartData( final List<double[]> ListOfAllSeries )
{
NumberFormat integerFormat = NumberFormat.getIntegerInstance();
ILineSeries lineSeries = (ILineSeries) chart.getSeriesSet().createSeries( SeriesType.LINE, "LineSeries" );
lineSeries.setYSeries( ListOfAllSeries.get( 1 ) );
lineSeries.setVisibleInLegend(false);
for(int i = 0; i < ListOfAllSeries.get(0).length; i++)
{
createBarSeries("BarSeries " + i,new double[] { series1.get(0)[i]}, new double[] {i},ListOfAllSeries.get(1)[i]);
}
xAxis.getTick().setFormat( integerFormat );
chart.getAxisSet().adjustRange();
chart.getAxisSet().getXAxis(0).setRange(new Range(-0.5, ListOfAllSeries.get(0).length - 0.5));
chart.redraw();
}
Index 0 of ListOfAllSeries always contains all bars data and in index 1 is line series data.
And here is createBarSeries function that creates bar series
private void createBarSeries(String seriesName, double[] yValues, double[] xValues, double lineValue)
{
IBarSeries barSeries = (IBarSeries) chart.getSeriesSet().createSeries(SeriesType.BAR,seriesName);
barSeries.setYSeries(yValues);
barSeries.setXSeries(xValues);
barSeries.setBarColor(yValues[0] > lineValue ? redColor : blueColor);
barSeries.setBarWidth(50);
barSeries.setBarPadding(0);
}
The problem is that bars, excluding the center bar, are shifted on the x-axis. For example, if there are supposed to be 3 bars, the center one will be in place but every other will be shifted from place and I want them to be exactly in the right spot. I tried different technics but nothing seems to work.