0

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: enter image description here

This image is a badly-displayed empty combined plot chart (No message for empty data and the domain axis's first value is truncated !): enter image description here

Overlapping and truncated labels for combined chart with data: enter image description here

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.

Community
  • 1
  • 1
Muhammad Gelbana
  • 3,890
  • 3
  • 43
  • 81

1 Answers1

0
  1. You could set a well-displayed, placeholder dataset that is initially invisible, and then replace it when real data is available.

  2. If rangeAxis.setVerticalTickLabels(false) isn't helpful, then I don't understand the question.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 1. I don't understand. 2. That would definitely help. But it would be much better to limit the height in which the label is displayed. Meaning, each label is written alongside each subplot's range axis, is there a way to limit the label's height to be equal to the relative subplot's height so the label is wrapped within the specified height ? Thank you. – Muhammad Gelbana Mar 11 '13 at 13:55
  • Edited: 1. I was thinking of this [example](http://stackoverflow.com/a/11895709/230513) with no series visible. 2. Ah, now I understand; AFAIK, wrapping is not supported. A `TextTitle` might be useful. – trashgod Mar 11 '13 at 21:02