gpt4 book ai didi

java - JFREECHART 折线图 : Want X axis to be collection of date ranges

转载 作者:太空宇宙 更新时间:2023-11-04 14:17:56 25 4
gpt4 key购买 nike

我是 JFreeChart 新手。我的要求是对于假设有 3 个变量的折线图,显示 X 轴(时间轴)如下(时间范围将根据用户输入进行配置):

8月3日-8月8日..8月10日-8月15日..[等等]

目前我的图表的 X 轴是这样的:

1..2..3..4..5 ..

[无法附加屏幕截图]

我的演示代码如下:

private JFreeChart createChart(final XYDataset dataset) {

// create the chart...
final JFreeChart chart = ChartFactory.createXYLineChart(
"Line Chart Demo ", // chart title
"X", // x axis label
"Y", // y axis label
dataset, // data
PlotOrientation.VERTICAL,
true, // include legend
true, // tooltips
false // urls
);

// OPTIONAL CUSTOMISATION OF THE CHART...
chart.setBackgroundPaint(Color.white);



// get a reference to the plot for further customisation...
final XYPlot plot = chart.getXYPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
renderer.setSeriesLinesVisible(0, true); //for line visibility
renderer.setSeriesShapesVisible(1, false);
plot.setRenderer(renderer);
// change the auto tick unit selection to integer units only...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
// final Axis range = plot.get

rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
// OPTIONAL CUSTOMISATION COMPLETED.

return chart;

}

有人能指出我正确的方向吗?如何仅获取 X 轴上显示的所需值?

最佳答案

XYPlot 域轴和范围轴之间存在差异。在您的情况下,X 轴是域轴,而 Y 轴是范围轴。

Valuexis domainAxis = plot.getDomainAxis();

您还可以设置不同的域轴:

ValueAxis dAxis = new ...
plot.setDomainAxis(dAxis);

关于java - JFREECHART 折线图 : Want X axis to be collection of date ranges,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27504161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com