Example graph depicting the desired outcome
I'm trying to create a chart with Chart.js which resembles the chart above...also if any other charting library makes this easier then please shout!
The chart needs to have:
I'm at a slight loss on how to do this natively by extending Chart.js so any help would be appreciated for custom chart examples or an idea of how to execute this.
var rangesStart = scale.calculateX(0);
var rangesEnd = scale.calculateX(23);
var gradient = this.chart.ctx.createLinearGradient(0, rangesStart, 0, rangesEnd);
ranges.forEach(function (range) {
gradient.addColorStop((scale.calculateX(range.start) - rangesStart) / (rangesEnd - rangesStart), range.color);
gradient.addColorStop((scale.calculateX(range.end) - rangesStart) / (rangesEnd - rangesStart), range.color);
})
I did attempt this here, but couldn't get the desired result, the colours seem to go horizontially instead of vertically.
http://jsfiddle.net/shxnhdfd/
Solved issues by using the beginPath() method
ctx.beginPath();
ranges.forEach(function (range) {
var numbersBetween = range.end - range.start
ctx.fillStyle = range.color;
ctx.fillRect(_this.datasets[0].points[range.start].x - 0 * unitX, yTop, unitX * numbersBetween, yHeight);
})
ctx.fill();
Working fiddle below:
http://jsfiddle.net/cvwporru/2/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With