diff --git a/docs/05-Pie-Doughnut-Chart.md b/docs/05-Pie-Doughnut-Chart.md index dd9de6f40..db2d9efd8 100644 --- a/docs/05-Pie-Doughnut-Chart.md +++ b/docs/05-Pie-Doughnut-Chart.md @@ -55,7 +55,7 @@ var data = [ ] ``` -For a pie chart, you must pass in an array of objects with a value and a color property. The value attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL. +For a pie chart, you must pass in an array of objects with a value and an optional color property. The value attribute should be a number, Chart.js will total all of the numbers and calculate the relative proportion of each. The color attribute should be a string. Similar to CSS, for this string you can use HEX notation, RGB, RGBA or HSL. ### Chart options diff --git a/samples/doughnut.color.html b/samples/doughnut.color.html new file mode 100644 index 000000000..5457fd094 --- /dev/null +++ b/samples/doughnut.color.html @@ -0,0 +1,58 @@ + + + + Doughnut Chart + + + + + +
+ +
+ + + + + diff --git a/src/Chart.Doughnut.js b/src/Chart.Doughnut.js index a892b0efc..0cfea145d 100644 --- a/src/Chart.Doughnut.js +++ b/src/Chart.Doughnut.js @@ -36,7 +36,6 @@ }; - Chart.Type.extend({ //Passing in a name registers this chart in the Chart namespace name: "Doughnut", @@ -73,6 +72,9 @@ this.calculateTotal(data); helpers.each(data,function(datapoint, index){ + if (!datapoint.color) { + datapoint.color = 'hsl(' + (360 * index / data.length) + ', 100%, 50%)'; + } this.addData(datapoint, index, true); },this); @@ -181,4 +183,4 @@ defaults : helpers.merge(defaultConfig,{percentageInnerCutout : 0}) }); -}).call(this); \ No newline at end of file +}).call(this);