mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-07 12:49:07 +02:00
31 lines
614 B
JavaScript
31 lines
614 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],
|
||
|
backgroundColor: 'black',
|
||
|
borderColor: 'orange',
|
||
|
fill: true,
|
||
|
segment: {
|
||
|
backgroundColor: ctx => slope(ctx) > 0 ? 'green' : slope(ctx) < 0 ? 'red' : undefined,
|
||
|
}
|
||
|
}]
|
||
|
},
|
||
|
options: {
|
||
|
plugins: {
|
||
|
legend: false
|
||
|
},
|
||
|
scales: {
|
||
|
x: {display: false},
|
||
|
y: {display: false}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
};
|