Sometime earlier I used to create default charts using the ChartFactory
createTimeseries
and createPieChart
static methods. And following up on that question, I wrote the following code that doesn't utilize these static methods any more. But after writing the following code to create combined plot charts, I can't reach a similar result (i.e. similar to charts created by ChartFactory
) when no data is available.
This image shows a well-displayed empty timeseries chart created by ChartFactory
:
This image is a badly-displayed empty combined plot chart (No message for empty data and the domain axis's first value is truncated !):
Overlapping and truncated labels for combined chart with data:
This is the combined plot chart code:
protected CombinedDomainXYPlot createDataset() {
CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(new DateAxis("Execution Date"));
TimeSeries tSeries = null;
XYPlot xyPlot = null;
XYLineAndShapeRenderer localXYLineAndShapeRenderer = null;
NumberAxis numberAxis = null;
for (ChartMetric metric : values.getChartMetrics()) {
tSeries = new TimeSeries(metric.getFinalDisplayName());
numberAxis = new NumberAxis(metric.getFinalDisplayName());
numberAxis.setAutoRangeIncludesZero(false);
for (Object[] row : values.getChartMetricValue(metric)) {
Second sec = new Second((Date) row[0]);
tSeries.add(sec, (Double) row[1]);
}
localXYLineAndShapeRenderer = new XYLineAndShapeRenderer(true, false);
xyPlot = new XYPlot(new TimeSeriesCollection(tSeries), null, numberAxis, localXYLineAndShapeRenderer);
xyPlot.setNoDataMessage("xy no data message");
combinedPlot.add(xyPlot);
}
combinedPlot.setGap(40.0D);
return combinedPlot;
}
protected JFreeChart createChart(CombinedDomainXYPlot combinedXYPlot) {
super.localJFreeChart = new JFreeChart(chartDetails.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, combinedXYPlot, true);
ChartFactory.getChartTheme().apply(localJFreeChart);
return chart;
}
To summer up:
. I need to display an empty combined domain chart in a well displayed way, like the single plot timeseries chart displayed (i.e. first image) . When successfully loading data for combined charts I need the range axis labels not to overlap. unfortunately, labels for the range axis could be VERY long some times. So if I can only wrap the label with respect to the subplot height, I guess that would do it.
Thank you for your time.