2017-07-11 196 views
2

按照chart.js documentation我可以指定邊界和背景的顏色數組。Chart.js - 每條邊界線有不同顏色的折線圖

但是,在chart.js中使用以下配置。我想弄清楚爲什麼borderColorbackgroundColor的數組值不工作。

我正在通過react-chartjs-2使用chart.js 2.6.0。這不是用chart.js v2開箱即用的嗎?

"{ 
"type": "Line", 
"labels": [ 
    "Monday", 
    "Tuesday", 
    "Wednesday", 
    "Thursday", 
    "Friday", 
    "Saturday", 
    "Sunday" 
], 
"datasets": [ 
    { 
    "label": "Page Views (This Week)", 
    "fill": false, 
    "lineTension": 0.1, 
    "backgroundColor": [ 
    "rgba(75,192,192, 0.4)", 
    "rgba(1, 223, 111, 0.4)", 
    "rgba(75,192,192, 0.4)", 
    "rgba(1, 223, 111, 0.4)", 
    "rgba(75,192,192, 0.4)" 
    ], 
    "borderColor": [ 
    "rgba(75,192,192, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(75,192,192, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(75,192,192, 1)" 
    ], 
    "borderCapStyle": "butt", 
    "borderDash": [], 
    "borderDashOffset": 0, 
    "borderJoinStyle": "miter", 
    "pointBorderColor": [ 
    "rgba(75,192,192, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(75,192,192, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(75,192,192, 1)" 
    ], 
    "pointBackgroundColor": "#fff", 
    "pointBorderWidth": 1, 
    "pointHoverRadius": 5, 
    "pointHoverBackgroundColor": "rgba(75,192,192, 1)", 
    "pointHoverBorderColor": "rgba(220,220,220,1)", 
    "pointHoverBorderWidth": 2, 
    "pointRadius": 1, 
    "pointHitRadius": 10, 
    "data": [ 
    19615, 
    37337, 
    54307, 
    70944, 
    87444 
    ] 
    }, 
    { 
    "label": "Page Views (Last Week)", 
    "fill": false, 
    "lineTension": 0.1, 
    "backgroundColor": [ 
    "rgba(242, 169, 12, 0.4)", 
    "rgba(1, 223, 111, 0.4)", 
    "rgba(242, 169, 12, 0.4)", 
    "rgba(1, 223, 111, 0.4)", 
    "rgba(242, 169, 12, 0.4)", 
    "rgba(1, 223, 111, 0.4)", 
    "rgba(242, 169, 12, 0.4)" 
    ], 
    "borderColor": [ 
    "rgba(242, 169, 12, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(242, 169, 12, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(242, 169, 12, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(242, 169, 12, 1)" 
    ], 
    "borderCapStyle": "butt", 
    "borderDash": [], 
    "borderDashOffset": 0, 
    "borderJoinStyle": "miter", 
    "pointBorderColor": [ 
    "rgba(242, 169, 12, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(242, 169, 12, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(242, 169, 12, 1)", 
    "rgba(1, 223, 111, 1)", 
    "rgba(242, 169, 12, 1)" 
    ], 
    "pointBackgroundColor": "#fff", 
    "pointBorderWidth": 1, 
    "pointHoverRadius": 5, 
    "pointHoverBackgroundColor": "rgba(242, 169, 12, 1)", 
    "pointHoverBorderColor": "rgba(220,220,220,1)", 
    "pointHoverBorderWidth": 2, 
    "pointRadius": 1, 
    "pointHitRadius": 10, 
    "data": [ 
    17819, 
    35785, 
    52761, 
    69470, 
    84987, 
    104958, 
    125497 
    ] 
    } 
] 
}" 

生成的圖形看起來像這樣,我期望交替的線段有替代的顏色。

enter image description here

回答

相關問題