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

时间:2014-11-21 15:40:12

标签: javascript charts lines chart.js

背景

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

问题

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

enter image description here

1 个答案:

答案 0 :(得分:3)

这可以通过将点的不透明度设置为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>