Search code examples
dygraphs

changing vertical bars color in a graph using Dygraph


I am designing a graph using Dygraph range selection option.The graph is represented using Vertical bars instead of line series. I have cases where there are more than two y-values for single x-value. Is it possible to give different colors for different bars when they overlap, so that identifying each bar becomes easy and usable. Any help would be greatly appreciated.

Thanks, Sunil


Solution

  • You can pass in an array of colors in the chart options:

    g = new Dygraph(document.getElementById("g_div"),
                     "X,Bar1,Bar2,Bar3\n" +
                     "1,10,11,12\n" +
                     "2,7,17,5\n" +
                     "3,6,23,12\n" +
                     "4,4,27,10\n" +
                     "5,3,30,23\n" +
                     "6,2,32,5\n" +
                     "7,1,33,17\n",
                       {
                         // options go here. See http://dygraphs.com/options.html
                         legend: 'always',
                         animatedZooms: true,
                         plotter: multiColumnBarPlotter,
                         colors: ["#00A0B0", "#6A4A3C", "#CC333F", ],
                         dateWindow: [0, 8]
                     });
    

    DEMO