如屏幕截图所示,有些天的值为空......我想用一条线连接数据集,而不管某个特定的天是否为空。这在chart.js 2.x中可能吗?
jogvjijk1#
您可以将spangap设置为true:
const options = { type: 'line', data: { labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"], datasets: [{ label: '# of Votes', data: [12, 19, 3, null, 2, 3], borderColor: 'pink', fill: false, spanGaps: true }, { label: '# of Points', data: [7, null, null, 8, 3, 7], borderColor: 'orange', fill: false, spanGaps: true } ] }, options: {} } const ctx = document.getElementById('chartJSContainer').getContext('2d'); new Chart(ctx, options);
<body> <canvas id="chartJSContainer" width="600" height="400"></canvas> <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script> </body>
xcitsw882#
您应该将spanGaps: true更改为spanGaps: false。https://www.chartjs.org/docs/latest/charts/line.html#line-styling
spanGaps: true
spanGaps: false
2条答案
按热度按时间jogvjijk1#
您可以将spangap设置为true:
xcitsw882#
您应该将
spanGaps: true
更改为spanGaps: false
。https://www.chartjs.org/docs/latest/charts/line.html#line-styling