gpt4 book ai didi

java - JFreeChart 隐藏(一些)x 轴值

转载 作者:行者123 更新时间:2023-11-30 07:21:23 25 4
gpt4 key购买 nike

我目前正在使用 JFreeChart 创建折线图。该折线图每秒更新一次新值(当前为随机值)。通过这种方式,您可以查看数据在特定时间段内的变化情况。然而,在我添加了十多个值之后,它们不再适合线上,变成了点。我希望一次只显示 5 个值,这些值分布在整个时间范围内。现在看起来是这样的: enter image description here

注意图表底部的点。我希望将其更改为: enter image description here请注意,我想保留这些时间点之间创建的所有点。因此 11:31:00、11:31:01、11:31:02 等的数据应该仍然存在。

这是我目前拥有的:

LocalDateTime date = LocalDateTime.now();

category = new DefaultCategoryDataset();
category.addValue(new Random().nextInt(10), "Data", date.getHour() + ":" + date.getMinute() + ":" + date.getSecond());

chart = ChartFactory.createLineChart("Values", "Time", "Data", category, PlotOrientation.VERTICAL, false, true, false);
((NumberAxis) ((CategoryPlot) chart.getPlot()).getRangeAxis()).setStandardTickUnits(NumberAxis.createIntegerTickUnits());

最佳答案

我通过使用 TimeSeriesChart 得到它。这就是我最终得到的结果:

TimeSeriesCollection collection = new TimeSeriesCollection();
TimeSeries serie = new TimeSeries("Data");
collection.addSeries(serie);

JFreeChart chart = ChartFactory.createTimeSeriesChart("Data", "Time", "Data", collection, false, true, false);

关于java - JFreeChart 隐藏(一些)x 轴值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37508334/

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