首页 > 解决方案 > 如何从chartjs中的所需点制作虚线?

问题描述

我需要在预设时间段内画一条虚线。我怎样才能在chartjs中做到这一点?例如,实线表示 3 个月,虚线表示其他

例子

下面的错误实现

var ctx = document.getElementById('myChart').getContext('2d');
var chart = new Chart(ctx, {
    // The type of chart we want to create
    type: 'line',

    // The data for our dataset
    data: {
        labels: ["January", "February", "March", "April", "May", "June", "July"],
        datasets: [{
            label: "Red",
            borderColor: 'rgb(255, 0, 0)',
            data: [0, 10, 5, 2, 20, 30, 45],
        }, {
            label: "Blue",
            borderColor: 'rgb(0, 0, 255)',
            data: [38, 24, 32],
        }, {
            label: "Blue",
            borderColor: 'rgb(0, 0, 255)',
            data: [null, null, 32, 0, 0, 0, 0],
            borderDash: [5, 5],
        }]
    },

    // Configuration options go here
    options: {}
});
.container {
  width: 640px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<div class='container'>
  <canvas id="myChart"></canvas>  
</div>

标签: charts

解决方案


推荐阅读