gpt4 book ai didi

javascript - Chart.js:为数据集设置不同的选项

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:00:28 27 4
gpt4 key购买 nike

背景

我想使用 Chartjs Lines 图表实现如下图所示。两条线,一根有点,一根没有点。我认为解决这个问题的方法是为两个数据集(线)设置不同的选项属性。

问题

图表数据集选项是为整个图表全局设置的。我无法为这两个数据集设置不同的选项。

enter image description here

最佳答案

这可以通过将点的不透明度设置为 0 来实现,这样它们就不会显示。

var data = {
labels: ["January", "February", "March", "April", "May", "June", "July"],
datasets: [{
label: "My First dataset",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [65, 59, 80, 81, 56, 55, 40]
}, {
label: "My Second dataset",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(0,0,0,0)",
pointStrokeColor: "rgba(0,0,0,0)",
pointHighlightFill: "rgba(0,0,0,0)",
pointHighlightStroke: "rgba(0,0,0,0)",
data: [28, 48, 40, 19, 86, 27, 90]
}]
};



var chart_canvas = document.getElementById("canvas").getContext("2d");
var line_chart = new Chart(chart_canvas).Line(data);
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1/Chart.js"></script>
<canvas id="canvas" height="450" width="600"></canvas>

关于javascript - Chart.js:为数据集设置不同的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27065018/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com