Set Separate Colors for Each Bar With App Script ColumChart Builder

Viewed 326

I am trying to set a individual color for each bar on a column chart that is rendered using a google app script. I am using the

.setColor(["color1", "color2", "color3"]) 

Method. This however leads to all the bars being set to color1. What do I need to change to have each bar be a different color

I have tried using

setOption("colors" : ["color1", "color2", "color3"]) 

but this does not work either.

Here is the code I am currently using:

var data = Charts.newDataTable()
    .addColumn(Charts.ColumnType.STRING, "Category")
    .addColumn(Charts.ColumnType.NUMBER, "Score")
    .addRow(["cat1", parseInt(m[0])])
    .addRow(["cat2", parseInt(m[1])])
    .addRow(["cat3", parseInt(m[2])])
    .addRow(["cat4", parseInt(m[3])])
    .addRow(["cat5", parseInt(m[4])])
    .build();

     var chart = Charts.newColumnChart()
      .setDimensions(1000, 1000)
      .setDataTable(data)
      .setRange(0,5)
      .setTitle(m[5] + "'s Chart")
      .setColors(["#6c564d", "#db5d52", "#3f4b5d", "#56be93", "#dce24b"])
      .build();

I want each category to have its own bar color but the colors are all the first color (category1's color)

0 Answers
Related