简体   繁体   中英

Configure two range axis in jFreeChart histogram

I have two series in a jFreeChart histogram. One is normally smaller then the other and we'd like to scale the smaller so it is similar to the larger series and I wanted to verify that it is possible to do this with jFreeChart's usual API and two separate range axis, presumably one on the right and the other on the left.

在此处输入图片说明

The official examples were quite helpful. Here is my solution based on them much thanks to trashgod's suggestion.

在此处输入图片说明

public void generateChart(List<FmsData> data, Valve valve) {

    HistogramDataset aggDs = createAggDataset(data);
    chart = createChart(aggDs, valve.getNumber());

    HistogramDataset valveDs = createValveDataset(data,valve.getNumber());
    XYPlot plot = chart.getXYPlot();

    // configure the second dataset
    plot.setDataset(0, aggDs);
    plot.setDataset(1, valveDs);
    plot.setRangeAxisLocation(0, AxisLocation.BOTTOM_OR_LEFT);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    plot.mapDatasetToRangeAxis(0, 0);
    plot.mapDatasetToRangeAxis(1, 1);

    NumberAxis valveRangeAxis = new NumberAxis();
    plot.setRangeAxis(1, valveRangeAxis);

    XYBarRenderer renderer2 = new XYBarRenderer();
    plot.setRenderer(1, renderer2);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    renderer2.setDrawBarOutline(false);
    // flat bars look best...
    renderer2.setBarPainter(new StandardXYBarPainter());
    renderer2.setShadowVisible(false);
    // end config second dataset

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM