[英]chart.js draw custom grid lines
在vue-chartjs
, renderChart()
的第二個參數是圖表的選項配置 ,其中可以包含scales.xAxes
和scales.yAxes
屬性以設置軸(即網格)的顏色:
this.renderChart( /* data */ , {
scales: {
xAxes: [{
display: true,
gridLines: {
display: true,
color: '#eee'
},
}],
yAxes: [{
display: true,
gridLines: {
display: true,
color: '#eee'
},
}]
}
})
Vue.component('line-chart', { extends: VueChartJs.Line, mounted () { this.renderChart({ labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'], datasets: [ { label: 'Data One', backgroundColor: '#f87979', data: [40, 39, 10, 40, 39, 80, 40] } ], }, { responsive: true, maintainAspectRatio: false, scales: { xAxes: [{ display: true, gridLines: { display: true, color: '#444' }, }], yAxes: [{ display: true, gridLines: { display: true, color: '#444' }, }] } }) } }) new Vue({ el: '.app', })
.app { background-image: radial-gradient(#2e3f61, #131b29); }
<script src="https://unpkg.com/vue@2.5.16"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js"></script> <script src="https://unpkg.com/vue-chartjs@3.0.1-rc2/dist/vue-chartjs.js"></script> <div class="app"> <line-chart></line-chart> </div>
查看您在刻度內定義的刻度字典> xAxes / yAxes。
選項autoskip:false和source:'data'應該起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.