gpt4 book ai didi

java - JFreeChart大数据无法读取轴

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

我正在使用 JFreeChart 绘制折线图。该应用程序每 100 毫秒读取一次感官数据,因此在几分钟的捕获中会产生大量数据。我不动态绘制图表,它是静态的。我使用类别图,因为轴有时可以是十进制值,有时可以是字符串,有时可以是 boolean 值。我的问题是 X 轴(时间)有太多数据,我无法辨认文本:

enter image description here

有人知道我在这里能做什么吗?任何处理这个问题的提示或技巧都会很棒!

 private CategoryDataset createDataset() {
String series1 = "First";
String series2 = "Second";
String category1 = "Category 1";
String category2 = "Category 2";
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for (int i = 0; i < time.size(); i++) {
dataset.addValue(Math.random(), series1, time.get(i));
}
return dataset;

}

private JFreeChart createChart(final CategoryDataset dataset) {

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

chart.setBackgroundPaint(Color.white);

final CategoryPlot plot = chart.getCategoryPlot();
plot.setBackgroundPaint(Color.white);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);

final CategoryItemRenderer renderer = (CategoryItemRenderer) plot.getRenderer();

plot.setRenderer(renderer);



return chart;

}

public void setLists(ArrayList<String> time) {
this.time = time;
final CategoryDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
setContentPane(chartPanel);
}

最佳答案

您可以通过添加以下内容来关闭标签和刻度线:

CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryAxis cx = new CategoryAxis();
cx.setTickLabelsVisible(false);
cx.setTickMarksVisible(false);
plot.setDomainAxis(cx);

如果您想显示标签的子集(每个第 n 个值),那么您需要对 CategoryAxis 进行子类化,以便可以覆盖 CategoryAxis#drawCategoryLabels()CategoryAxis#drawTickMarks()

关于java - JFreeChart大数据无法读取轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20340911/

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