Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ChartJS not rendering lines according to x-axis data

Data:

const data={
  "labels": [
    0,  
    400,
      800,
      1200,
      1600,
      2000,
      2400,
      2800,
      3200,
      3600,
      4000
  ],
  "datasets": [
    {
      "axis": 'x',
      "label": "FFF",
      "borderColor": "Red",
      "backgroundColor": "Red",
      "data": [
          {
              "x": 2883,
              "y": 129
          },
          {
              "x": 3509,
              "y": 118
          },
          {
              "x": 3916,
              "y": 73
          }
      ]
  }
  ]
};

Chart:
enter image description here

I am providing both x & y axis values, the result should be like this for red line.
But for current config it rendering the line from start instead of specific point on x-axis.
enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You have to use scatter chart and showline : true option instead of line chart for this result.

//your code

const data={
  "labels": [
    0,  
    400,
      800,
      1200,
      1600,
      2000,
      2400,
      2800,
      3200,
      3600,
      4000
  ],
  "datasets": [
    {
      "axis": 'x',
      "label": "FFF",
      "borderColor": "Red",
      "backgroundColor": "Red",
      "showLine": true,         //add this option to connect dots of scatterred points
      "data": [
          {
              "x": 2883,
              "y": 129
          },
          {
              "x": 3509,
              "y": 118
          },
          {
              "x": 3916,
              "y": 73
          }
      ]
  }
  ]
};

<Scatter data={data} />
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading