Barchart with positive and negative colours?

Hi all,

Just wondering if anyone knows of a chart plugin that can do positive and negative colours?

Just want a simple bar chart that displays a colour if the value is positive and a different colour if the value is negative.

You could set this as a conditional on the chart itself mostlikely. Tried that yet?

If not, I imagine you can probably plugin a plug-in like List Shifter or JavaScript toolbox to output a list of colors based on an input list of value

I did something like that from my calendar Plugin. For an event titled texts I wanted it to be dynamic so that no matter what color the event was the text was still visible so the user inputs a dark and a light color and based on the color of the events I created a script that outlets in the appropriate contrasting

I’m sure you could whip up some cold like that pretty quickly honestly for your use case it would be much simpler

conditional doesn’t work as there wouldn’t be a condition to set colour base on individual data value.
All I need is default colour = Green, if the value is less than 0, then colour=red for a bar chart.

Many of the chart plugins I played around with doesn’t have the option to change colour if a value is negative. Should be a fairly simple thing to implement (I think).

you could use the jstoolbox and this code

    // your input values
    let val_arr = [-1,-3,5,6,-10,10]
    //your negative color
    let neg_color = 'black'
    //your positive color
    let pos_color = 'red'

    //this does the magic to create the appropriate output list
    let array_out = val_arr.map(x=>{
    	return x > 0 ? pos_color : neg_color
    })

    //print the values to the console
    console.log(array_out)

if you cant get a list out of the toolbox and only a string, you could use regex to extract a comma delimited list!

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.