Melon1228 2023-12-20 15:02 采纳率: 0%
浏览 16

Java JfreeChart StackedAreaChart堆叠面积图x轴数据量过大时和密集怎么解决?

Java JfreeChart StackedAreaChart堆叠面积图x轴数据量过大时和密集怎么解决?

/**
     * Creates a sample dataset.
     *
     * @return A sample dataset.
     */
    public CategoryDataset createDataset(List<RowData> list) {
        double[][] data = new double[list.size()][list.get(0).getColValMap().size()];
        // 定义行键
        Comparable[] rowKeys = new Comparable[list.size()];
        // 定义列键
        Comparable[] columnKeys = new Comparable[list.get(0).getColValMap().size()];
        int c = 0;
        for (Integer index : list.get(0).getColValMap().keySet()) {
            columnKeys[c++] = index;
        }
        for (int i = 0; i < list.size(); i++) {
            Map<Integer, Object> colValMap = list.get(i).getColValMap();
            int j = 0;
            for (Integer index : colValMap.keySet()) {
                double value = ObjectUtils.isEmpty(colValMap.get(index)) ? 0 : Double.valueOf(colValMap.get(index) + "");
                data[i][j++] = value;
            }
            rowKeys[i] = list.get(i).getName();
        }
        /*final double[][] data = new double[][] {
                {1.0, 4.0, 3.0, 5.0, 5.0, 7.0, 7.0, 8.0 },
                {5.0, 7.0, 6.0, 8.0, 4.0, 4.0, 2.0, 1.0 },
                {4.0, 3.0, 2.0, 3.0, 6.0, 3.0, 4.0, 3.0 }
        };*/

        final CategoryDataset dataset = DatasetUtils.createCategoryDataset(
                rowKeys, columnKeys, data
        );
        return dataset;
    }

    /**
     * Creates a sample chart.
     *
     * @param dataset  the dataset.
     *
     * @return A sample chart.
     */
    public JFreeChart createChart(CategoryDataset dataset) {

        final JFreeChart chart = ChartFactory.createStackedAreaChart(
                "Stacked Area Chart",      // chart title
                "Category",                // domain axis label
                "Value",                   // range axis label
                dataset,                   // data
                PlotOrientation.VERTICAL,  // orientation
                true,                      // include legend
                true,
                false
        );

        chart.setBackgroundPaint(Color.white);

        final CategoryPlot plot = (CategoryPlot) chart.getPlot();
        plot.setForegroundAlpha(0.5f);
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        //是否显示网格线
        plot.setDomainGridlinesVisible(false); // hide horizontal gridlines
        plot.setRangeGridlinesVisible(false); // hide vertical gridlines

        // 设置图的背景为白色
        plot.setBackgroundPaint(Color.WHITE);
        // 设置背景虚线的颜色
        plot.setRangeGridlinePaint(Color.decode("#B6A2DE"));
        // 去掉堆叠面积图的背景边框,使边框不可见
        plot.setOutlineVisible(false);
        // 设置标题的字体样式
        chart.getTitle().setFont(new Font("微软雅黑", Font.PLAIN, 24));
        // 设置图表下方图例上的字体样式
        chart.getLegend().setItemFont(new Font("微软雅黑", Font.PLAIN, 12));

        final CategoryAxis domainAxis = plot.getDomainAxis();
        domainAxis.setLowerMargin(0.0);

        // change the auto tick unit selection to integer units only...
        final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        final CategoryItemRenderer renderer = plot.getRenderer();
        //renderer.setItemLabelsVisible(true);

        return chart;

    }

img

  • 写回答

1条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2023-12-26 01:44
    关注

    【相关推荐】




    如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^
    评论

报告相同问题?

问题事件

  • 创建了问题 12月20日

悬赏问题

  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口
  • ¥15 如何能达到用ping0.cc检测成这样?如图
  • ¥15 关于#DMA固件#的问题,请各位专家解答!
  • ¥15 matlab生成的x1图不趋于稳定,之后的图像是稳定的水平线
  • ¥15 请问华为OD岗位的内部职业发展通道都有哪些,以及各个级别晋升的要求
  • ¥20 微信小程序 canvas 问题
  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式