Base.prototype.COLORSET = ['#f3c300', '#875692', '#f38400', '#a1caf1', '#be0032', '#c2b280', '#7f180d', '#008856',
'#e68fac', '#0067a5'];
+ /**
+ * Set of colours defined by setting $CFG->chart_colorset to be picked when automatically assigning them.
+ *
+ * @type {String[]}
+ * @protected
+ */
+ Base.prototype._configColorSet = null;
+
/**
* The type of chart.
*
// Give a default color from the set.
if (series.getColor() === null) {
- series.setColor(Base.prototype.COLORSET[this._series.length % Base.prototype.COLORSET.length]);
+ var configColorSet = this.getConfigColorSet() || Base.prototype.COLORSET;
+ series.setColor(configColorSet[this._series.length % configColorSet.length]);
}
};
// TODO Not convinced about the usage of Klass here but I can't figure out a way
// to have a reference to the class in the sub classes, in PHP I'd do new self().
var Chart = new Klass();
-
+ Chart.setConfigColorSet(data.config_colorset);
Chart.setLabels(data.labels);
Chart.setTitle(data.title);
data.series.forEach(function(seriesData) {
return axis;
};
+ /**
+ * Get colours defined by setting.
+ *
+ * @return {String[]}
+ */
+ Base.prototype.getConfigColorSet = function() {
+ return this._configColorSet;
+ };
+
/**
* Get the labels of the X axis.
*
return this.__getAxis('y', index, createIfNotExists);
};
+ /**
+ * Set colours defined by setting.
+ *
+ * @param {String[]} colorset An array of css colours.
+ * @protected
+ */
+ Base.prototype.setConfigColorSet = function(colorset) {
+ this._configColorSet = colorset;
+ };
+
/**
* Set the defaults for this chart type.
*
Pie.prototype.addSeries = function(series) {
if (series.getColor() === null) {
var colors = [];
+ var configColorSet = this.getConfigColorSet() || Base.prototype.COLORSET;
for (var i = 0; i < series.getCount(); i++) {
- colors.push(this.COLORSET[i % Base.prototype.COLORSET.length]);
+ colors.push(configColorSet[i % configColorSet.length]);
}
series.setColors(colors);
}