我查看了其他示例,但未找到回答此问题的示例。我在java中使用jFreePanel。我正在尝试创建一个折线图,标有年度变化的X轴(即:2005,2006,2007等)。数据由每天读取的数据组成,因此不可能指出每一个数据,但按年份分解这些数据似乎非常合理。不过,我正在努力弄清楚如何去做。
所以,而不是......
X-axis __________________________________________________________________________________
2000-01-01 to 2009-06-30
看起来应该是这样......
X-axis __________________________________________________________________________________
2000 2001 2002 2003 2004 2005 2006 2007 2008 2009
2000-01-01 to 2009-06-30
相关代码在这里......
private JFreeChart createChart(final CategoryDataset dataset) {
// create the chart...
final JFreeChart chart = ChartFactory.createLineChart(
site, // chart title
firstDate + " to " + DBChart.lastDate, // domain axis label
"Height", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // orientation
false, // exclude legend
false, // tooltips
false // urls
);
chart.setBackgroundPaint(Color.white);
final CategoryPlot plot = (CategoryPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setRangeGridlinePaint(Color.white);
// Customize the range axis...
final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
chart.getCategoryPlot().getRangeAxis().setRange(getLowestLow(data), getHighestHigh(data));
rangeAxis.setAutoRangeIncludesZero(false);
// Customize the renderer...
final LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
renderer.setSeriesShapesVisible(0, false);
return chart;
}
private double getLowestLow(Object data[][]) {
double lowest;
lowest = Double.parseDouble(data[0][2].toString());
System.out.println(lowest);
for (int i = 1; i < data.length - 1; i++) {
if (data[i][2] != null) {
if (Double.parseDouble(data[i][2].toString()) < lowest) {
lowest = Double.parseDouble(data[i][2].toString());
}
}
}
return lowest;
}
private double getHighestHigh(Object data[][]) {
double highest;
highest = Double.parseDouble(data[0][2].toString());
for (int i = 1; i < data.length - 1; i++) {
if (data[i][2] != null) {
if (Double.parseDouble(data[i][2].toString()) > highest) {
highest = Double.parseDouble(data[i][2].toString());
}
}
}
return highest;
}
感谢另一个主题,我能够自定义Y轴,但我没有找到有关如何用X轴做我想做的事情的信息而我从未使用过这个图书馆之前。任何帮助将不胜感激。