Chart.js/test/fixtures/controller.line/segments/slope.js
Jukka Kurkela 4eb59454be
Allow styling of line segments (#8844)
Allow styling of line segments

* docs & sample
* Types
* update sample
2021-04-08 18:02:12 -04:00

27 lines
572 B
JavaScript

function slope({p0, p1}) {
return (p0.y - p1.y) / (p1.x - p0.x);
}
module.exports = {
config: {
type: 'line',
data: {
labels: ['a', 'b', 'c', 'd', 'e', 'f'],
datasets: [{
data: [1, 2, 3, 3, 2, 1],
borderColor: 'black',
segment: {
borderColor: ctx => slope(ctx) > 0 ? 'green' : slope(ctx) < 0 ? 'red' : undefined,
borderDash: ctx => slope(ctx) < 0 ? [5, 5] : undefined
}
}]
},
options: {
scales: {
x: {display: false},
y: {display: false}
}
}
}
};