JFreeChart 日期问题

JFreeChart issue with dates

您好,我无法在 JFreeChart 中显示日期。但是,日期包含在 TimeSeries 中。这是我在调试器中看到的:

但我唯一能看到的是:

这是我的代码:

public XYDataset createDataset() {
        TimeSeries series1 = new TimeSeries(PortfolioValueChart.CHART_NAME_PORTFOLIO);
        for (PriceAction pa : positionPrices.getPrices()) {
            series1.add(pa.date.toRegularTimePeriod(), pa.close);
        }

        TimeSeriesCollection dataset = new TimeSeriesCollection();
        dataset.addSeries(series1);
        return dataset;
    }

JFreeChart portfolioValueChart = PortfolioValueChart.getChart(financialPosition);
ChartPanel portfolioValuePanel = new ChartPanel(portfolioValueChart);

记得用

TimeSeriesChart

如:

JFreeChart chart = ChartFactory.createTimeSeriesChart(...)

使用 Javadoc:

public static JFreeChart createTimeSeriesChart​(String title,
String timeAxisLabel,
String valueAxisLabel,
XYDataset dataset,
boolean legend,
boolean tooltips,
boolean urls)
Creates and returns a time series chart. A time series chart is an XYPlot with a DateAxis for the x-axis and a NumberAxis for the y-axis. The default renderer is an XYLineAndShapeRenderer.
A convenient dataset to use with this chart is a TimeSeriesCollection.

Parameters:
title - the chart title (null permitted).
timeAxisLabel - a label for the time axis (null permitted).
valueAxisLabel - a label for the value axis (null permitted).
dataset - the dataset for the chart (null permitted).
legend - a flag specifying whether or not a legend is required.
tooltips - configure chart to generate tool tips?
urls - configure chart to generate URLs?
Returns:
A time series chart.