JFreeChart StackedXYAreaRenderer causes “crimp” in chart

眉间皱痕 提交于 2019-12-01 12:03:35
trashgod

ChartFactory.createStackedXYAreaChart() instantiates StackedXYAreaRenderer2 to avoid this problem. Your example replaces it with an instance of StackedXYAreaRenderer. Either,

  • Use the factory's renderer and a custom DateAxis.

    private JFreeChart createChart(TimeTableXYDataset chartData) {
        JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Dogs and Cats", "Time", "Count", chartData,
            PlotOrientation.VERTICAL, false, true, false);
        DateAxis dateAxis = new DateAxis();
        dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateAxis.setTickLabelFont(dateAxis.getTickLabelFont().deriveFont(20f));
        XYPlot plot = (XYPlot) chart.getPlot();
        plot.setDomainAxis(dateAxis);
        return chart;
    }
    
  • Recapitulate the factory, as shown here, in your createChart() method.

    private JFreeChart createChart(TimeTableXYDataset chartData) {
        DateAxis dateAxis = new DateAxis("Time");
        dateAxis.setDateFormatOverride(new SimpleDateFormat("HH:mm"));
        dateAxis.setTickLabelFont(dateAxis.getTickLabelFont().deriveFont(20f));
        NumberAxis yAxis = new NumberAxis("Count");
        XYToolTipGenerator toolTipGenerator = new StandardXYToolTipGenerator();
        StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2(
            toolTipGenerator, null);
        renderer.setOutline(true);
        XYPlot plot = new XYPlot(chartData, dateAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);
        plot.setRangeAxis(yAxis);  // forces recalculation of the axis range
        JFreeChart chart = new JFreeChart("Dogs and Cats",
            JFreeChart.DEFAULT_TITLE_FONT, plot, false);
        new StandardChartTheme("JFree").apply(chart);
        return chart;
    }
    

Can you expand a little bit on why the StackedXYRenderer causes that crimp?

The author writes, "StackedXYAreaRenderer2 uses a different drawing approach, calculating a polygon for each data point and filling that." In contrast, StackedXYAreaRenderer appears to close a single Shape by connecting the endpoints with a straight line.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!