Search code examples
androidshinobi

Padding between bars when using multiple BarSeries in shinobi


As a follow up to my other question, I still have the problem described there (big padding between bars), but this time the scenario is using different series. I'm using different series because of a limitation in Shinobi where, if you want each bar of a different color, you need to use different series. See here.

The code I'm using is the following:

        DataAdapter<Integer, Integer> dataAdapter3 = new SimpleDataAdapter<Integer, Integer>();
        dataAdapter3.add(new DataPoint<Integer, Integer>(3, 3));
        BarSeries ls3 = new BarSeries();
        ls3.setDataAdapter(dataAdapter3);
        BarSeriesStyle bss3 = ls3.getStyle();
        bss3.setAreaColor(Color.CYAN);

        DataAdapter<Integer, Integer> dataAdapter2 = new SimpleDataAdapter<Integer, Integer>();
        dataAdapter2.add(new DataPoint<Integer, Integer>(12, 2));
        BarSeries ls2 = new BarSeries();
        ls2.setDataAdapter(dataAdapter2);
        BarSeriesStyle bss2 = ls2.getStyle();
        bss2.setAreaColor(Color.GREEN);

        DataAdapter<Integer, Integer> dataAdapter1 = new SimpleDataAdapter<Integer, Integer>();
        dataAdapter1.add(new DataPoint<Integer, Integer>(1, 1));
        BarSeries ls1 = new BarSeries();
        ls1.setDataAdapter(dataAdapter1);
        BarSeriesStyle bss1 = ls1.getStyle();
        bss1.setAreaColor(Color.BLUE);

        DataAdapter<Integer, Integer> dataAdapter0 = new SimpleDataAdapter<Integer, Integer>();
        dataAdapter0.add(new DataPoint<Integer, Integer>(15, 0));
        BarSeries ls0 = new BarSeries();
        ls0.setDataAdapter(dataAdapter0);
        BarSeriesStyle bss0 = ls0.getStyle();
        bss0.setAreaColor(Color.YELLOW);

        NumberAxis xAxis = new NumberAxis();
        chart.setXAxis(xAxis);
        NumberAxis yAxis = new NumberAxis();
        chart.setYAxis(yAxis);
        yAxis.getStyle().setInterSeriesSetPadding(0.0f);
        yAxis.getStyle().setInterSeriesPadding(0.0f);

        chart.addSeries(ls3);
        chart.addSeries(ls2);
        chart.addSeries(ls1);
        chart.addSeries(ls0);

Result:

enter image description here

As a side, note also that bars are not aligned at the right values on the Y axis (0->0.8, 1->1.2, 2->1.8, 3->2.7)


Solution

  • I've ran your code and I get exactly the same output. The solution is to set the stack id to be equal for each of the bar series. For example: ls3.setStackId(1); ls2.setStackId(1);.....

    This should work. Thanks, Kai.

    Disclaimer: I work for ShinobiControls.