如何使用JFReechart创建双X轴图?带有冲刺名称的时间表

发布于 2025-01-25 11:52:43 字数 1539 浏览 5 评论 0原文

我正在用JFree图表挣扎在双X轴图表上。在使用图表定制器进行了几次试验之后,它仍然不起作用。我想在数据源中的轴上有基于事件的标签。问题是第二个X轴未显示。 这是我的代码:

public class BurnupTimelineChartCustomizer extends JRAbstractChartCustomizer {
private static final String Y_AXIS_MAX_VALUE = "yaxisMaxValue";

private static final String EXPECTED_TOTAL_SCOPE = "expectedTotalScope";
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {

    Double yaxisMaxValue = (Double) this.getParameterValue(Y_AXIS_MAX_VALUE);
    Double expectedTotalScope = (Double) this.getParameterValue(EXPECTED_TOTAL_SCOPE);
    CategoryPlot plot = chart.getCategoryPlot();

    // Value Marker
    ValueMarker marker = new ValueMarker(Math.max(yaxisMaxValue,expectedTotalScope));
    marker.setPaint(Color.black);
    plot.addRangeMarker(marker);
    // Dual Axis
    CategoryAxis sprintAxis = new CategoryAxis("TimeLine Axis");
    plot.setDomainAxis(1, sprintAxis );
    plot.mapDatasetToDomainAxis(1, 1);      // Range Axis

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setUpperBound(Math.max(expectedTotalScope, yaxisMaxValue) +100);
    rangeAxis.setLowerBound(0.);
    rangeAxis.setVisible(false);

    // Dashed line
    LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer(true, true);
    lineAndShapeRenderer.setSeriesPaint(0,Color.black);
    lineAndShapeRenderer.setBaseItemLabelsVisible(Boolean.TRUE);
    lineAndShapeRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    plot.setRenderer(lineAndShapeRenderer);
}}

I'm struggling with the dual X-axis chart with jfree chart. After a few trials with a chart customizer it still doesn't work. I would like to have events based labels on the axis that are in my datasource. The problem is the second x-axis does not show.
Here is my code:

public class BurnupTimelineChartCustomizer extends JRAbstractChartCustomizer {
private static final String Y_AXIS_MAX_VALUE = "yaxisMaxValue";

private static final String EXPECTED_TOTAL_SCOPE = "expectedTotalScope";
@Override
public void customize(JFreeChart chart, JRChart jasperChart) {

    Double yaxisMaxValue = (Double) this.getParameterValue(Y_AXIS_MAX_VALUE);
    Double expectedTotalScope = (Double) this.getParameterValue(EXPECTED_TOTAL_SCOPE);
    CategoryPlot plot = chart.getCategoryPlot();

    // Value Marker
    ValueMarker marker = new ValueMarker(Math.max(yaxisMaxValue,expectedTotalScope));
    marker.setPaint(Color.black);
    plot.addRangeMarker(marker);
    // Dual Axis
    CategoryAxis sprintAxis = new CategoryAxis("TimeLine Axis");
    plot.setDomainAxis(1, sprintAxis );
    plot.mapDatasetToDomainAxis(1, 1);      // Range Axis

    ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setUpperBound(Math.max(expectedTotalScope, yaxisMaxValue) +100);
    rangeAxis.setLowerBound(0.);
    rangeAxis.setVisible(false);

    // Dashed line
    LineAndShapeRenderer lineAndShapeRenderer = new LineAndShapeRenderer(true, true);
    lineAndShapeRenderer.setSeriesPaint(0,Color.black);
    lineAndShapeRenderer.setBaseItemLabelsVisible(Boolean.TRUE);
    lineAndShapeRenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());

    plot.setRenderer(lineAndShapeRenderer);
}}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文