Hi everyone. I have an enquiry on the legend not updating with a pareto bar chart (using the Configure Chart function) in a Vision window.
I have created a Downtime Pareto chart of issues related to the downtime of an asset. The data source is populated with varying issue types. The problem with using the standard bar graph was that the color of each issue series did not remain the same when the downtime duration of issues changed, specifically in a pareto format. As a result, I was able to utilize the ConfigureChart function to fix the color of each issue series. But the legend does not update accordingly.
The following is the Downtime Pareto chart along with the dataset. When comparing the dataset with the chart, you should notice that the legend is not updated to the fixed colors and is defaulting to its randomly generated colors.
I have done some research and testing with updating/overriding the legend via the ConfigureChart but I am not experiencing much success. There are a lot of examples of updating and overriding legends for XY Scatter Plots which I believe does not work exactly the same for Category or Bar graphs.
Has anyone been able to do something similar to the following example? Otherwise, is my approach in fixing the colors of the graph incorrect?
Any help on this matter is greatly appreciated.
Code sample of the fixing of series colors is below:
def configureChart(self, chart):
"""
Provides an opportunity to perform further chart configuration via
scripting. Doesn't return anything.
Arguments:
self: A reference to the component that is invoking this function.
chart: A JFreeChart object. Refer to the JFreeChart documentation for
API details.
"""
import java.awt
from java.awt import Color
from org.jfree.chart.renderer.category import BarRenderer
from org.jfree.chart.renderer.category import StandardBarPainter
from org.jfree.chart import LegendItem
class CustomRenderer(BarRenderer):
def getItemPaint(self, row, column):
v = chart.getCategoryPlot().getDataset().getRowKey(row)
if v == "Issue 1":
return Color(128,128,128)
elif v == "Issue 2":
return Color(255,0,255)
elif v == "Issue 3":
return Color(255,140,0)
elif v == "Issue 4":
return Color(255,255,0)
elif v == "Issue 5":
return Color(0,255,0)
elif v == "Issue 6":
return Color(0,255,255)
elif v == "Issue 7":
return Color(0,0,255)
elif v == "Issue 8":
return Color(255,0,0)
elif v == "Issue 9":
return Color(213,213,213)
elif v == "Issue 10":
return Color(255,138,138)
elif v == "Issue 11":
return Color(255,202,138)
elif v == "Issue 12":
return Color(255,255,138)
elif v == "Issue 13":
return Color(138,255,138)
elif v == "Issue 14":
return Color(138,255,255)
elif v == "Issue 15":
return Color(138,138,255)
elif v == "Issue 16":
return Color(255,138,255)
elif v == "Issue 17":
return Color(43,43,43)
elif v == "Issue 18":
return Color(172,0,0)
elif v == "Issue 19":
return Color(172,95,0)
chart.getCategoryPlot().setRenderer(CustomRenderer())
chart.getPlot().getRenderer().setBarPainter(StandardBarPainter())
chart.getPlot().getRenderer().setShadowVisible(0)