jfreechart - setting the bar column color based on the state in StackedBarChart

泪湿孤枕 提交于 2019-12-12 02:58:33

问题


I have 2 questions:

  1. How to set the date axis range in jfreechart? The starting date should be 6days before current day & end date should be current day. So that there would be only 7 values in x-axis (dateaxis).

I am trying the following code, but it is not working:

    XYPlot plot = (XYPlot) jfreechart.getPlot();
    dateaxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
    plot.setRangeAxis(dateaxis);
  1. How to set specific color for the specific column of bar based on the state value? i.e, if i am adding "success" state on 6th sept & "failure" state on 7h sept & "success" state on 8th sept, then how do i represent them as green-red-green?

I am trying to add the the data in the following way. But colors are not actually changing based on state even if i override GradientPaint & setSeriesPaint function:

For the category named F7, i am adding the data in the following way.

defaultcategorydataset.addValue(6/8/2014 , "Successful", "F7");
defaultcategorydataset.addValue(7/8/2014 , "Failed", "F7");
defaultcategorydataset.addValue(8/8/2014 , "Successful", "F7");
defaultcategorydataset.addValue(9/8/2014 , "Failed", "F7");
defaultcategorydataset.addValue(10/8/2014 , "Successful", "F7");
defaultcategorydataset.addValue(11/8/2014 , "Successful", "F7");

Finally i am expecting the graph to be like this (In the screenshot F7 category is not properly represented according to the added value):

来源:https://stackoverflow.com/questions/25873131/jfreechart-setting-the-bar-column-color-based-on-the-state-in-stackedbarchart

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