Vue ChartKick - different colours for bar chart

女生的网名这么多〃 提交于 2020-12-12 07:02:47

问题


I use a vertical bar chart and I want to specify different colors for each bar:

main.js

import Chartkick from 'vue-chartkick';
import Chart from 'chart.js';
Vue.use(Chartkick.use(Chart));

File.vue

<column-chart :data="chartData" width="800px" :colors="['#0b6e00', '#006ca2', '#ff3333', '#d60001']"></column-chart>

But only the first color is used and all bars have the same colour.

I tried to pass a :library attribute with backGround colour parameter as well without luck. Line chart accepts different colours.


回答1:


It will work if you define :colors as a nested array as follows:

<column-chart 
  :data="chartData" 
  width="800px" 
  :colors="[['#0b6e00', '#006ca2', '#ff3333', '#d60001']]">
</column-chart>

Please have a look at the following StackBlitz



来源:https://stackoverflow.com/questions/61127225/vue-chartkick-different-colours-for-bar-chart

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!