Hi everyone,
I have this bar chart (pictured below) that is returning 2 series of data from a dynamic date range. I am wanting to change the bar color of the first series based on if the value is higher or lower than the second series. I imagine there is a way I can do this in the getBarColor function (green if greater than, red if less than), I just don't know how. Can anyone help me out with this?
Also, here is my sql query for this chart if that's helpful:
Correct. Simply check the next column for the current row in the chart's dataset to the current value anytime series one is being evaluated by the extension function.
Example:
#def getBarColor(self, [...] defaultColor):
# This script assumes that the "Exact Order" parameter is set to "By Row"
# Define the necessary colors
seriesOneHighValueColor = system.gui.color('lightgreen')
# These two variables can be explicitly defined in the script,
# ...or the extension function's defaultColor variable can be used to simply return the default color for each series
seriesOneDefaultColor = system.gui.color('lightblue')
seriesTwoDefaultColor = system.gui.color('darkgrey')
# chart data zero indexed columns = [Label, Series 1, Series 2]
# The series variable in the extension function is zero indexed,
# ...so series == 0 will be Series 1 and series == 1 will be Series 2
# The category variable represents a row index in the chart's dataset
# If Series 1 is being evaluated,
# ...and its row value is greater than the series 2 value on the same row of data,
# ...apply a special color. Otherwise, use the default colors for the respective series
if series == 0 and value > self.data.getValueAt(category, 2):
return seriesOneHighValueColor
elif series == 0:
return seriesOneDefaultColor # or simply defaultColor
else:
return seriesTwoDefaultColor # or simply defaultColor
Result:
![image](https://global.discourse-cdn.com/inductiveautomation/original/3X/2/9/2980ca9e8b2cd9f81e3e4e614620239612eac379.png)
2 Likes