To convert the double into date format using a class in JFreeChart

后端 未结 1 846
自闭症患者
自闭症患者 2021-01-25 10:39

I would like to know, if it is possible to set the both parameter as date, which in this example it take the first parameter as comparable and the second as double. But i want t

相关标签:
1条回答
  • 2021-01-25 11:14

    Instead of a NumberAxis, use a DateAxis. That will let you use a DateFormat in the setDateFormatOverride() method.

    Update: There's a complete example in org.jfree.chart.demo.TimeSeriesChartDemo1. You might want createLineChart(). Here's hoe you'd make the range axis show dates.

    public class Example1 {
    
        public static void main(String args[]) {
            DefaultKeyedValues data = new DefaultKeyedValues();
            data.addValue("8/4/2012", new Day(8, 4, 2012).getFirstMillisecond());
            data.addValue("19/04/2012", new Day(19, 4, 2012).getFirstMillisecond());
            CategoryDataset dataset = DatasetUtilities
                .createCategoryDataset("Population", data);
    
            JFreeChart chart = ChartFactory.createLineChart("Population", "Date",
                "Population", dataset, PlotOrientation.VERTICAL, true, true, false);
            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
            renderer.setBaseShapesVisible(true);
            renderer.setBaseLinesVisible(false);
    
            DateAxis range = new DateAxis("Date");
            range.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
            plot.setRangeAxis(range);
    
            ChartFrame frame = new ChartFrame("Test", chart);
            frame.pack();
            frame.setVisible(true);
        }
    }
    
    0 讨论(0)
提交回复
热议问题