CharlieShi
CharlieShi

Reputation: 916

How to change chart series line color in Dojo?

I am now using Dojo to show a line chart. but I don't know how to change the series line color, would anyone help? thx.

  var chart1 = new dc.Chart("test1");
  chart1.addPlot("default", { type: "Default", lines: true, markers: true, tension: 1 });
  chart1.addAxis("x", { majorTick: { stroke: "black", length: 5 }, minorTick: { stroke: "black", length: 1} });
  chart1.addAxis("y", { vertical: true, majorTick: { stroke: "black", length: 5 }, minorTick: { stroke: "black", length: 1} });
  chart1.addSeries("Series A", [{ x: 0.5, y: 5 }, { x: 1.5, y: 1.5 }, { x: 2, y: 9 }, { x: 5, y: 0.3}]);
  chart1.addSeries("Series B", [{ x: 0.3, y: 8 }, { x: 4, y: 6, tooltip: "Custom tooltip" }, { x: 5.5, y: 2}]);
  chart1.addSeries("Series C", [{ x: 0.8, y: 6 }, { x: 8, y: 1, tooltip: "Custom tooltip" }, { x: 7, y: 2}]);
  chart1.addSeries("Series D", [{ x: 0.1,y: 5}, { x: 2, y: 3, tooltip: "Custom tooltip" }, { x: 4, y: 5}]);

  var anim1a = new dc.action2d.Magnify(chart1, "default");
  var anim1b = new dc.action2d.Tooltip(chart1, "default");
  chart1.render();

for Series A, Series B,Series C,Series D,I want to use my-defined color to show them, anyone can help?

Upvotes: 0

Views: 1267

Answers (2)

Christophe
Christophe

Reputation: 744

You can probably also provide the color in your series for it to be used by the plot. Something like the following:

chart1.addSeries("Series A",
        [{ x: 0.5, y: 5 }, { x: 1.5, y: 1.5 }, { x: 2, y: 9 }, { x: 5, y: 0.3}], 
        { stroke: "green" });

Upvotes: 2

MiBrock
MiBrock

Reputation: 1100

You can change the colors by using the setTheme() function while defining your chart.

Must look like :

require(["dojox/charting/Chart", "dojox/charting/themes/Shrooms", "dojox/charting/plot2d/Areas", ...],
function(Chart, Shrooms, Areas, ...){
   new Chart(node)
   addPlot("default", { type: Areas, tension: "X" })
   setTheme(Shrooms)
   addSeries("Series A", [1, 2, 0.5, 1.5, 1, 2.8, 0.4])
   addSeries("Series B", [2.6, 1.8, 2, 1, 1.4, 0.7, 2])
   addSeries("Series C", [6.3, 1.8, 3, 0.5, 4.4, 2.7, 2])
  render();
});

In this example the Theme "Shrooms" will be loaded.

Here you can see, what themes are available for Charts:

http://demos.dojotoolkit.org/demos/chartTypes/demo.html

and in the dojo API you can find them under dojox/charting/themes.

Here's a good tutorial how you can define themes by yourself: http://dojotoolkit.org/documentation/tutorials/1.9/charting/

Regards, Miriam

Upvotes: 0

Related Questions