我正在使用JFreeChart绘制折线图。该应用程序每100毫秒读取一次感官数据,所以在几分钟的捕获中,这是一个很多数据。我不动态绘制图形,它是静态的。我正在使用类别图,因为轴有时可以是十进制值,有时它可以是字符串,有时它可以是布尔值。我的问题是X轴(时间)有太多的数据我无法弄清楚文字:
任何人都知道我能在这做什么吗?处理这个的任何提示或技巧都会很棒!
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);
}
答案 0 :(得分:0)
您可以添加:
来关闭Lables和TickMarksCategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryAxis cx = new CategoryAxis();
cx.setTickLabelsVisible(false);
cx.setTickMarksVisible(false);
plot.setDomainAxis(cx);
如果要显示标签的子集(每第n个值),则需要子类CategoryAxis
,以便覆盖CategoryAxis#drawCategoryLabels()
和CategoryAxis#drawTickMarks()