Chartjs linechart with only one point - how to center

后端 未结 4 1190
一整个雨季
一整个雨季 2020-12-19 01:45

I have a chartjs linechart diagram to show the sales of different products on a range of dates. The user can select a date range (for example from 2015-12-01 to 2015-12-10)

4条回答
  •  不思量自难忘°
    2020-12-19 01:59

    You can check the length of your labels (or data) arrays and add dummy non-renderable points to the left and right by using empty string labels and null value, like so

    var chartData = {
      labels: ['', "A", ''],
      datasets: [
        {
          fillColor: "rgba(255, 52, 21, 0.2)",
          pointColor: "#da3e2f",
          strokeColor: "#da3e2f",
          data: [null, 20, null]
        },
        {
          fillColor: "rgba(52, 21, 255, 0.2)",
          strokeColor: "#1C57A8",
          pointColor: "#1C57A8",
          data: [null, 30, null]
        },
      ]
    }
    

    Fiddle - https://jsfiddle.net/pf24vg16/

提交回复
热议问题