OL Learn

Bar Chart - change the color of the first bar

good morning people

I am inheriting a template made by a colleague who changed his job, to which I have to make a change in the bar graph, I know that the best thing would be to do the whole graph again, but now is not the time, I classify it as pending.
my question is the following: can the color of the first bar be overwritten with a script?
I leave the graph, thank you very much in advance!

image

Good Afternoon,

There should be a script in the Scripts panel at the left sid of your screen which refers to this chart. Usually you can change the colors in the window that opens when you double click on this script. If this doesn’t work for you, please contact your local support department and we’ll be happy to help you.

Best regards,
Eline

Hi Eline

Yes, all that works, and the bars are already assigned a certain color, (gray), what I need is to change the color of only the first bar (black).

Good Afternoon,

In that case I have to see your specific setup to find a solution. Please contact your local support department and send them your datamapper and template so that we can help you.

Thank you.

Best regards,
Eline

Try the following:

Create a new user script after the Graph/Bar script. The new script should use the same selector.

Add the following code:

var amchart = JSON.parse( results.attr('data-amchart') );

amchart.graphs[0].colorField     = "mycolor";
amchart.graphs[0].lineColorField = "mycolor";

amchart.dataProvider[0].mycolor = '#FF99CC';
results.attr('data-amchart', JSON.stringify( amchart ));

It reads the chart configuration. Subsequently it sets the data property name for the line color and fill color. Next it assigns this property with a custom color value to first record in the data and writes the result back to the attribute used for the chart configuration.

It seems to work for a standard bar chart.

Hope this helps,

Erik

Perfect!!! it was what I needed.
thank you very much Erik.

Glad it helped!
Erik