javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -
i try , create radar chart using chart.js has various colours each scaleline, or coloured between scalelines. wondering if possible?
from:
to:
i have working graph, though there doesn't seem method change individual scale lines.
kind regards leigh
you can extend radar chart type this, so
chart.types.radar.extend({ name: "radaralt", initialize: function (data) { chart.types.radar.prototype.initialize.apply(this, arguments); var originalscaledraw = this.scale.draw; var ctx = this.chart.ctx; this.scale.draw = function () { var linewidth = this.linewidth; // bypasses line drawing in originalscaledraw this.linewidth = linewidth; originalscaledraw.apply(this, arguments); ctx.linewidth = this.linewidth; var scale = this; // draw chart.helpers.each(scale.ylabels, function (label, index) { // color of each radial line - replace array lookup (if limit scalesteps) ctx.strokestyle = "hsl(" + index / scale.ylabels.length * 360 + ", 80%, 70%)"; // copy of chart.js code ctx.beginpath(); (var = 0; < scale.valuescount; i++) { pointposition = scale.getpointposition(i, scale.calculatecenteroffset(scale.min + (index * scale.stepvalue))); if (i === 0) { ctx.moveto(pointposition.x, pointposition.y); } else { ctx.lineto(pointposition.x, pointposition.y); } } ctx.closepath(); ctx.stroke(); }); } } });
and call so
var ctx = document.getelementbyid("mychart").getcontext("2d"); var myradarchart = new chart(ctx).radaralt(data, { scalelinewidth: 10 }); // requried if have animation: false // myradarchart.update();
fiddle - http://jsfiddle.net/x3ftqx5r/
of course, sane thing change lightness value instead of hue value :-)
Comments
Post a Comment