简体   繁体   English

在 jFreeChart 直方图中配置两个范围轴

[英]Configure two range axis in jFreeChart histogram

I have two series in a jFreeChart histogram.我在 jFreeChart 直方图中有两个系列。 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.一个通常比另一个小,我们希望缩放更小,因此它类似于更大的系列,我想验证是否可以使用 jFreeChart 的常用 API 和两个单独的范围轴来做到这一点,大概一个在右边和另一个在左边。

在此处输入图片说明

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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