1
我'指的這個帖子2.1.6背景色:chart.js之每一部分
chart.js Line chart with different background colors for each section
,我不能使它與chart.js之版本2.1.6工作(API有改變),任何想法?
我'指的這個帖子2.1.6背景色:chart.js之每一部分
chart.js Line chart with different background colors for each section
,我不能使它與chart.js之版本2.1.6工作(API有改變),任何想法?
我這樣做:
Chart.pluginService.register({
beforeDraw: function (chart, easing) {
if (chart.chartArea) {
var helpers = Chart.helpers;
var ctx = chart.chart.ctx;
var chartArea = chart.chartArea;
var chartWidth = chartArea.right - chartArea.left;
var chartHeight = Math.abs(chartArea.top - chartArea.bottom);
ctx.save();
var pattern = document.createElement('canvas');
pattern.width = 40;
pattern.height = chartHeight;
var pctx = pattern.getContext('2d');
pctx.fillStyle = "#f0f2f5";
pctx.fillRect(0, 0, 20, chartHeight);
pctx.fillStyle = "#ffffff";
pctx.fillRect(20, 0, 20, chartHeight);
var pattern = ctx.createPattern(pattern, "repeat");
ctx.fillStyle = pattern;
ctx.fillRect(chartArea.left, chartArea.top, chartArea.right - chartArea.left, chartArea.bottom - chartArea.top);
ctx.restore();
}
});
這是一個方法,如何做到這一點https://stackoverflow.com/questions/37144031/background-colour-of-line-charts-in-chart-js/ 47674241#47674241 – niksi