1

如何在 chartJS 折线图中实现这种点?

在此处输入图像描述

4

1 回答 1

5

这是一个获取您所追求的点样式的示例:

可以在此处找到折线图点选项的文档

下面代码的codePen在这里

HTML:

<html>
  <body>
    <div class="myChartDiv">
      <canvas id="myChart" width="600" height="400"></canvas>
    </div>
  </body>
</html>

JS:

new Chart(document.getElementById("myChart"), {
  type: "line",
  data: {
    labels: ["January", "February", "March", "April", "May", "June"],
    datasets: [
      {
        label: "My First Dataset",
        data: [20, 25, 22, 19, 31, 40],
        fill: true,
        borderColor: "rgb(75, 192, 192)",
        backgroundColor: "rgba(0,0,0,0.1)",
        borderWidth: 2,
        lineTension: 0,
        /* point options */
        pointBorderColor: "blue", // blue point border
        pointBackgroundColor: "white", // wite point fill
        pointBorderWidth: 1, // point border width
      }
    ]
  },
  options: {
    legend: {
      labels: {
        usePointStyle: true, // show legend as point instead of box
        fontSize: 10 // legend point size is based on fontsize
      }
    }
  }
});
于 2017-11-14T17:10:46.497 回答