在XYJfree图表中自定义条形颜色 [英] Customize bar colors in XYJfree chart

查看:121
本文介绍了在XYJfree图表中自定义条形颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何绘制不同颜色的不同条形图,我尝试使用渲染器,这是我的示例代码:

how to paint different bars in different colors, I tried to use renderer, here is my sample code:

    public IntervalXYDataset createDataset() throws InterruptedException {
    parseFile();
    final XYSeries series = new XYSeries("Analysis");

    int i=0;
    while(parsedArray[i]!=0)
        {

        series.add(xaxisArray[i], yaxisArray[i]);

        i++;
    }

    final XYSeriesCollection dataset = new XYSeriesCollection(series);

     dataset.setIntervalWidth(0.15);//set width here

    return dataset;
}

这就是我绘制图表的方式:

and this is how I am drawing the graph:

public className (final String title) throws InterruptedException {
    super(title);
    IntervalXYDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    final ChartPanel chartPanel = new ChartPanel(chart);
     XYPlot plot = (XYPlot) chart.getPlot();
    plot.getRenderer().setSeriesPaint( 0, Color.black);//0 works and paints all 40 bars in black, 1 and above fails. 
             // plot.getRenderer().setSeriesPaint( 1, Color.green);// this fails
    chartPanel.setPreferredSize(new java.awt.Dimension(2000,1000));//(width,height) of display
    setContentPane(chartPanel);

}






I我可以设置我在程序中评论的宽度,但是我现在想要设置不同条形的颜色,例如我想在图表中获取条形并为数组[0]绘制红色,为[3]绘制蓝色]和橙色的细胞[17],请你指导我。非常感谢你。


I am able to set the width as I have commented in my program, however I now want to set the color for different bars, for example I want to get hold of bar in chart and draw red for array[0] and blue for [3] and orange for cell[17], can you please guide me on this. Thank you very much.

推荐答案

我找到答案
创建两个系列,然后添加您想要的酒吧数量并为每个系列设置颜色。使用setSeriesPaint

I found the answer Create two series, and then add how many ever bars you want and set color for each series. using setSeriesPaint

这篇关于在XYJfree图表中自定义条形颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆