[英]JFreeChart Large Data Can't Read Axis
I am using JFreeChart to plot a line graph. 我正在使用JFreeChart绘制折线图。 The app reads in sensory data every 100 milliseconds so for a few minutes of capture it's aa lot of data.
该应用程序每100毫秒读取一次感官数据,因此在捕获的几分钟内,其中包含大量数据。 I don't plot the graph dynamically, it is static.
我不会动态绘制图形,它是静态的。 I am using a Category plot since the axis can sometimes be decimal values, other times it can be strings, other times it can be boolean.
我正在使用类别图,因为轴有时可以是十进制值,有时可以是字符串,有时可以是布尔值。 My issue is the X axis (time) has so much data I can't make out the text:
我的问题是X轴(时间)有太多数据,我无法辨认出文本:
Anyone know what I can do here to? 有人知道我在这里可以做什么吗? Any tips or tricks to deal with this will be great!
处理这个的任何技巧都将很棒!
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);
}
You can turn off the Lables and TickMarks by adding: 您可以通过添加以下内容来关闭标签和刻度标记:
CategoryPlot plot = (CategoryPlot) chart.getPlot();
CategoryAxis cx = new CategoryAxis();
cx.setTickLabelsVisible(false);
cx.setTickMarksVisible(false);
plot.setDomainAxis(cx);
If you wantto display a subset of the labels (every nth value) then you will need to subclass CategoryAxis
so you can overide CategoryAxis#drawCategoryLabels()
and CategoryAxis#drawTickMarks()
如果要显示标签的子集(每n个值),则需要对
CategoryAxis
进行子CategoryAxis
以便可以覆盖CategoryAxis#drawCategoryLabels()
和CategoryAxis#drawTickMarks()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.