Chart.js: [FEATURE] Mixed Charts for Line and Scatter

Created on 28 Sep 2017  ·  3Comments  ·  Source: chartjs/Chart.js

I am wondering if it is possible to have a mixed line and scatter chart.

With this data:

var chartData = { 
      datasets: [{
          type: "scatter",
          label: "My First dataset",
          data: [{
              x: 200,
              y: 200
          }, {
              x: 0,
              y: 0
          }]
      }, {type: "scatter",
          label: "My Second dataset",
          data: [{
              x: randomScalingFactor() + 100,
              y: randomScalingFactor() + 100
          }, {
              x: randomScalingFactor() + 100,
              y: randomScalingFactor() + 100
          }]
      }, {
        type: 'line',
        label: 'Line Dataset 1',
        data: [{x: 10,
            y: 20},{x: 4,
            y: 16}]
  }, {
        type: 'line',
        label: 'Line Dataset 2',
        data: [{x: 10,
            y: 44},{x: 33,
            y: 19}]
  }]
  };

When I try

window.myChart = Chart.Line(ctx, {
          data: chartData,
          options: options
      });

And

window.myChart = Chart.Scatter(ctx, {
          data: chartData,
          options: options
      });

The chart only comes up as either 4 lines in the former case, or 4 series of scatter plots in the latter case.

If there is no workaround to getting this working, then adding the functionality to add both points and lines onto a single chart would be greatly appreciated.

Thanks

Most helpful comment

Legend, thanks for the help.

I made a small JFiddle using your fix if anyone is interested:
https://jsfiddle.net/zvm7eoma/2/

All 3 comments

Make them all line charts, but turn off showLine for the scatter charts

http://www.chartjs.org/docs/latest/charts/line.html

Legend, thanks for the help.

I made a small JFiddle using your fix if anyone is interested:
https://jsfiddle.net/zvm7eoma/2/

Closing as answered

Was this page helpful?
0 / 5 - 0 ratings