Quantcast
Channel: Pentaho Community Forums
Viewing all articles
Browse latest Browse all 16689

Change the axis of a series on a line chart

$
0
0
I have a line chart with 4 series on it, I need to change one serie to another axis, here is some code in beanshell for that purpose:

Code:

/*************** code ********************/
CategoryPlot chartPlot = chart.getCategoryPlot();
ValueAxis yAxis= chartPlot.getRangeAxis();
data = chartPlot.getDataset();
rKeys = data.getRowKeys();
cKeys = data.getColumnKeys();
ArrayList dataVals = new ArrayList();
int nrKeys = rKeys.size();
int ncKeys = cKeys.size();
String title = "Test axis change";
DefaultCategoryDataset ds1 = new DefaultCategoryDataset();
DefaultCategoryDataset ds2 = new DefaultCategoryDataset();


for (int i=0;i<nrKeys-1;i++)
{
    for(int j=0;j<ncKeys;j++)
    {
        ds1.addValue(data.getValue(i,j),rKeys.get(i).toString(), cKeys.get(j).toString());
    }
    chart.setTitle(title);
}
int i = nrKeys-1;
for (int j=0;j<ncKeys;j++)
{
    ds1.addValue(0,"",cKeys.get(j).toString());
    ds2.addValue(data.getValue(i,j),"HOURS ON", cKeys.get(j).toString());
}


chartPlot.setDataset(0,ds1);
chartPlot.setDataset(1,ds2);


chartPlot.mapDatasetToRangeAxis(1, 1);


CategoryAxis categoryaxis = chartPlot.getDomainAxis();
categoryaxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
NumberAxis numberaxis = new NumberAxis("Secondary");
chartPlot.setRangeAxis(1, numberaxis);
LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(true,false);
lineandshaperenderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator());
chartPlot.setRenderer(1, lineandshaperenderer);
chartPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);


chart.setTitle(title);

/******************* end  code ******************/

I have tested the code in a jfreechart demo and works OK, but in Report Designer the series doesn't shows.

Thaks in advance ...

Viewing all articles
Browse latest Browse all 16689

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>