【发布时间】:2018-11-01 12:59:32
【问题描述】:
我正在使用 ChartJS V2 创建图表。 Chartjs V2 支持填充颜色功能。但我想用不同的颜色填充重叠区域。 请看下面的截图。我有两条线。 A表示两条线的重叠区域。
我想为 2 行填充 3 种不同的颜色。 当 Line1 和 Line2 重叠时,填充颜色应为 A 如果 Line1 不与 Line2 重叠,则填充颜色应为 B 如果 Line2 不与 Line1 重叠,则填充颜色应为 C
我为此添加了一个小提琴。 见小提琴http://jsfiddle.net/qcs1t9ag/
谢谢!
var lineChartData = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
data: [50, 85, 56, 50, 60, 70, 80],
yAxisID: "y-axis-1",
borderColor: "#0ad4e6"
}, {
label: "My Second dataset",
data: [35, 45, 75, 40, 55, 50, 62],
yAxisID: "y-axis-2",
borderColor: "#f6c63e"
}]
};
var ctx = document.getElementById("canvas").getContext("2d");
window.myLine = Chart.Line(ctx, {
data: lineChartData,
options: {
responsive: true,
hoverMode: 'label',
stacked: false,
title: {
display: false,
text: 'Chart.js Line Chart - Multi Axis'
},
animation: {
duration: 0
},
legend: {
display: false,
position: 'top',
},
scales: {
xAxes: [{
display: true,
gridLines: {
offsetGridLines: false
}
}],
yAxes: [{
type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: "left",
id: "y-axis-1",
scaleLabel: {
display: true,
labelString: "Cost"
}
}, {
type: "linear", // only linear but allow scale type registration. This allows extensions to exist solely for log scale for instance
display: true,
position: "right",
id: "y-axis-2",
scaleLabel: {
display: true,
labelString: "Students",
},
// grid line settings
gridLines: {
drawOnChartArea: false, // only want the grid lines for one axis to show up
},
}],
}
}
});
【问题讨论】:
标签: javascript canvas chart.js chartjs-2.6.0