0

我的问题是我不知道如何以这种格式 00:00:00.000 将时间分配给 JFreeChart 中的 X 轴。

我正在编写一个应用程序,它将从 CSV 文件中获取数据,其中列如下所示:

时间加速度X加速度Y加速度Z

例如,我看了看,但没有找到任何可能对我有帮助的东西。

我的代码:

public ChartService() {

        final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis("Time"));
        this.datasets = new TimeSeriesCollection[SUBPLOT_COUNT];

        for (int i = 0; i < SUBPLOT_COUNT; i++) {
            this.lastValue[i] = 100.0;
            final TimeSeries series = new TimeSeries(Y_AXIS_TITLES[i], Millisecond.class);
           // this.series.add(new SimpleDateFormat("hh:mm:ss.mmm"), 0.2222);

            this.datasets[i] = new TimeSeriesCollection(series);
            final NumberAxis rangeAxis = new NumberAxis(Y_AXIS_TITLES[i]);
            rangeAxis.setAutoRangeIncludesZero(false);
            final XYPlot subplot = new XYPlot(
                    this.datasets[i], null, rangeAxis, new StandardXYItemRenderer()
            );
            subplot.setBackgroundPaint(Color.lightGray);
            subplot.setDomainGridlinePaint(Color.white);
            subplot.setRangeGridlinePaint(Color.white);
            plot.add(subplot);
        }

        final JFreeChart chart = new JFreeChart("Dynamic Data Demo 3", plot);

        chart.setBorderPaint(Color.black);
        chart.setBorderVisible(true);
        chart.setBackgroundPaint(Color.white);

        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);

        final ValueAxis axis = plot.getDomainAxis();
        axis.setAutoRange(true);
        axis.setFixedAutoRange(60000.0);  // 60 seconds

        final JPanel content = new JPanel(new BorderLayout());

        final ChartPanel chartPanel = new ChartPanel(chart);
        content.add(chartPanel);

        chartPanel.setPreferredSize(new java.awt.Dimension(790, 620));
        chartPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
        this.add(content);

    }

请帮忙 !!!

4

1 回答 1

1
    String s = "10:00:00.000";
    SimpleDateFormat f = new SimpleDateFormat("HH:MM:SS.SSS");

    Date parsedDate = f.parse(s);

您可以如上所述将给定时间转换为日期,然后您可以使用 Date 对象创建 http://www.jfree.org/jfreechart/api/gjdoc/org/jfree/data/time/Millisecond.html#Millisecond:日期

于 2012-04-18T18:58:04.413 回答