Java 在jfreechart TimesPeriesCollection中,如何显示只有值的日期?
我已经编写了上面的代码,它工作得非常好,但是在渲染图形时,它显示的日期没有值。它在y轴上显示日期,如2012年4月9日、2012年4月10日至2012年4月18日,这些日期没有值。如何删除没有值的日期。为什么会这样 有人能帮我吗Java 在jfreechart TimesPeriesCollection中,如何显示只有值的日期?,java,jfreechart,Java,Jfreechart,我已经编写了上面的代码,它工作得非常好,但是在渲染图形时,它显示的日期没有值。它在y轴上显示日期,如2012年4月9日、2012年4月10日至2012年4月18日,这些日期没有值。如何删除没有值的日期。为什么会这样 有人能帮我吗 时间序列连续显示,这意味着即使该日期没有实际值,日期也沿轴均匀分布。如果只希望显示某些日期,则应使用某种类型的。时间序列将连续显示,这意味着即使此日期没有实际值,日期也沿轴均匀分布。如果您只想显示某些日期,则应使用某种类型的。请尝试以下方法: public class
时间序列连续显示,这意味着即使该日期没有实际值,日期也沿轴均匀分布。如果只希望显示某些日期,则应使用某种类型的。时间序列将连续显示,这意味着即使此日期没有实际值,日期也沿轴均匀分布。如果您只想显示某些日期,则应使用某种类型的。请尝试以下方法:
public class Example {
public static void main(String args[]){
/*creating timeSeriesCollection*/
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries timeSeries1 = new TimeSeries("Sample 1");
timeSeries1.add(new Day(8,4, 2012), 7.0);
timeSeries1.add(new Day(19,4, 2012), 5.0);
dataset.addSeries(timeSeries1);
/*Creating the chart*/
JFreeChart chart = ChartFactory.createTimeSeriesChart("Population","Date","Population",dataset,true,true,false);
/*Altering the graph */
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
NumberAxis numberAxis = (NumberAxis)plot.getRangeAxis();
numberAxis.setRange(new Range(0,10));
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));
axis.setAutoTickUnitSelection(false);
axis.setVerticalTickLabels(true);
/* Displaying the chart*/
ChartFrame frame = new ChartFrame("Test", chart);
frame.pack();
frame.setVisible(true);
}
}
不要使用TimeSeriesChart
将CategoryDataSet用作@Dirk sugested,然后切换到LineandShaperEnder
尝试以下操作:
public class Example {
public static void main(String args[]){
/*creating timeSeriesCollection*/
TimeSeriesCollection dataset = new TimeSeriesCollection();
TimeSeries timeSeries1 = new TimeSeries("Sample 1");
timeSeries1.add(new Day(8,4, 2012), 7.0);
timeSeries1.add(new Day(19,4, 2012), 5.0);
dataset.addSeries(timeSeries1);
/*Creating the chart*/
JFreeChart chart = ChartFactory.createTimeSeriesChart("Population","Date","Population",dataset,true,true,false);
/*Altering the graph */
XYPlot plot = (XYPlot) chart.getPlot();
plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0));
plot.setDomainCrosshairVisible(true);
plot.setRangeCrosshairVisible(true);
XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer)plot.getRenderer();
renderer.setBaseShapesVisible(true);
renderer.setBaseShapesFilled(true);
NumberAxis numberAxis = (NumberAxis)plot.getRangeAxis();
numberAxis.setRange(new Range(0,10));
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy"));
axis.setAutoTickUnitSelection(false);
axis.setVerticalTickLabels(true);
/* Displaying the chart*/
ChartFrame frame = new ChartFrame("Test", chart);
frame.pack();
frame.setVisible(true);
}
}
不要使用
TimeSeriesChart
使用CategoryDataSet作为@Dirk sugested,然后切换到lineandshaperender
+1以获得一个好的示例并确认@Dirk。使用不同的轴和渲染器,可能值得放弃工厂。+1作为一个好例子,并承认@Dirk。使用不同的轴和渲染器,可能值得放弃工厂。