wailiuya
2011-09-28 10:11
浏览 255
已采纳

jfreechar柱状图中,如何设置最高值与最低值以及中间值三类柱的颜色?

jfreechar柱状图中,如何设置最高值与最低值以及中间值三类柱的颜色?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • caizi1288 2011-09-28 16:54
    已采纳

    [code="java"] String FONT="宋体";
    JFreeChart localJFreeChart = ChartFactory.createBarChart(this.title, "", "金额(元)", paramCategoryDataset, PlotOrientation.VERTICAL, false, true, false);
    localJFreeChart.setBackgroundPaint(new Color(255, 255, 255));
    CategoryPlot localCategoryPlot = (CategoryPlot)localJFreeChart.getPlot();
    CategoryAxis localCategoryAxis = localCategoryPlot.getDomainAxis();
    localCategoryAxis.setMaximumCategoryLabelWidthRatio(0.8F);
    localCategoryAxis.setLowerMargin(0.02D);
    localCategoryAxis.setUpperMargin(0.02D);
    NumberAxis localNumberAxis = (NumberAxis)localCategoryPlot.getRangeAxis();
    localNumberAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    BarRenderer localBarRenderer = (BarRenderer)localCategoryPlot.getRenderer();
    localBarRenderer.setDrawBarOutline(false);
    [color=red] GradientPaint localGradientPaint = new GradientPaint(0.0F, 0.0F, Color.green, 0.0F, 0.0F, Color.white);[/color] localBarRenderer.setSeriesPaint(0, localGradientPaint);

    TextTitle textTitle = localJFreeChart.getTitle();
    textTitle.setFont(new Font(FONT, Font.PLAIN, 20));

    CategoryPlot plot = localJFreeChart.getCategoryPlot();
    CategoryAxis domainAxis = plot.getDomainAxis();
    ValueAxis rAxis = plot.getRangeAxis();
    /*------设置X轴坐标上的文字-----------*/
    domainAxis.setTickLabelFont(new Font(FONT, Font.PLAIN, 12));
    /*------设置X轴的标题文字------------*/
    domainAxis.setLabelFont(new Font(FONT, Font.PLAIN, 12));
    /*------设置Y轴坐标上的文字-----------*/
    rAxis.setTickLabelFont(new Font(FONT, Font.PLAIN, 12));
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.DOWN_45);
    /*------设置Y轴的标题文字------------*/
    rAxis.setLabelFont(new Font(FONT, Font.PLAIN, 12));

      return localJFreeChart;[/code]
    

    红字是设置柱的颜色及样式。
    设置最高值与最低值以及中间值,你说这种估计不行吧。有几个柱状都是根据数据自动生成的。颜色也是统一设置的。

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题