score:1
Try this, This link may be helpful to you http://www.chartjs.org/docs/latest/charts/scatter.html
var ctx = document.getElementById("myChart");
var scatterChart = new Chart(ctx, {
type: 'scatter',
data: {
datasets: [{
label: 'Scatter Dataset',
data: [{x: 0, y: 65},
{x: 4, y: 59},
{x: 100, y: 80},
{x: 110, y: 81},
{x: 125, y: 56}]
}]
},
options: {
scales: {
xAxes: [{
type: 'linear',
position: 'bottom'
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.1.3/Chart.js"></script>
<canvas id="myChart" width="400" height="400"></canvas>
Edit: Why We use Scatter chart instead of line Chart? Line Chart is use when we want to plot data set on same difference,and data structure is one dimensional array, for example, data: [20, 10] then we use line chart.
But When we want plot data on different differences and data structure is 2 dimensional array then we use scatter chart. for example, data: [{ x: 10, y: 20 }, { x: 15, y: 10 }]
score:1
Point objects ( {x:2, y:4}) can be interpreted by line chart and should be displayed correctly if you just specified a labels key before the datasets key:
data: {
labels:["a","b","c",...]
datasets: [{
label: 'my Dataset',
data: [{x: 0, y: 65},
{x: 4, y: 59},
{x: 100, y: 80},
{x: 110, y: 81},
{x: 125, y: 56}]
}]
},
note that the labels array and the data object inside the datasets should have the same number of elements.
score:15
To help those who are stuck on this in 2019 (Chart.js 2.0), please see below :
For those who prefer to dig into the details and form your own inferences, You can refer to the chartjs example at https://www.chartjs.org/samples/latest/scales/time/line-point-data.html (go and view its source).
For those who want a quick answer: In short you can maintain your existing code, but add the following options: (I re-append Shaz's code for completeness)
new Chart(document.getElementById("chartjs-0"), {
"type":"line",
"data": {
"datasets": [
{
"label":"My First Dataset",
"data": [
{x: 0, y: 65},
{x: 4, y: 59},
{x: 100, y: 80},
{x: 110, y: 81},
{x: 125, y: 56}
],
"fill":false,
"borderColor":"rgb(75, 192, 192)",
"lineTension":0.1
}
]
},
// this is the part that will make it work... see .. xAxes type:'linear'
"options":{
responsive: true,
title: {
// optional: your title here
},
scales: {
xAxes: [{
type: 'linear', // MANDATORY TO SHOW YOUR POINTS! (THIS IS THE IMPORTANT BIT)
display: true, // mandatory
scaleLabel: {
display: true, // mandatory
labelString: 'Your label' // optional
},
}],
yAxes: [{ // and your y axis customization as you see fit...
display: true,
scaleLabel: {
display: true,
labelString: 'Count'
}
}],
}
}
}
);
Source: stackoverflow.com
Related Query
- line chart with {x, y} point data displays only 2 values
- ChartJS - Line chart issue with only 1 point
- How to display Line Chart dataset point labels with Chart.js?
- ChartJS: Draw vertical line at data point on chart on mouseover
- ChartJs line chart - display permanent icon above some data points with text on hover
- Is it possible to revert x-axe values in line chart with chart.js
- Chart JS: Ignoring x values and putting point data on first available labels
- How to show data values in top of bar chart and line chart in chart.js 3
- chart js with angular2 loading dynamic data only after zoomin
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- react-chartjs-2 line chart with time on X-axes with multiple data sets plotted wrong
- Empty circle - only point strok in line chart for ChartJS
- Drawing line chart in chart.js with json data
- Line Chart using Chart js with time data
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- Real-time line chart with ChartJS using Ajax data
- Chart.js combined line and bar chart with differing data points
- Chart.js How can I embed additional values to each data point in radar chart
- Chart Piechart in only show percentage on hover but it shows data and label with percentage both i just want to show percentage only percentage
- How to dynamically update data of line chart used with chart Js?
- Can chart.js display text associated with each point on a line chart that is permanently visible?
- How to plot line chart with multiple datas, but only 2 labels?
- Show label for every data point in line chart
- How to configure chart.js line chart with very low minimum height, and only 0 and 1 (no decimals) as ticks on the y-axis
- Multiple axis line chart with Chart.js and JSON data from Google Sheet
- Position of the x-axis labels is not in sync with the line chart data points
- Add data to line chart js dynamically with multiple lines
- Plot a Line chart using Chart.js with CSV Data
- How to set data values as labels in Chart.js with a Radar Chart
- How can I create a horizontal scrolling Chart.js line chart with a locked y axis?
More Query from same tag
- Chartjs, How to edit data option after creating a chart?
- How to display Tooltip without hovering pie chart with Chart.JS
- Getting TypeError: (intermediate value).Bar is not a function with react and chart.js
- Custom tooltip styling in Chart.js
- how to use chart.js in angular 7
- Chart.js - consolidating days to month totals along the x (time) axis?
- New Chart.js Chart onclick
- How to change font size of labeled scales in Chart.js?
- Is it possible to shorten outer labels on Radar graph using Chart.js, without affecting the other labels?
- Is it possible to have a canvas next to another canvas without space on the bottom?
- Dynamically created Chart.js chart overpopulating time based x-axis?
- ChartJS adding shadow color to grid and custom x-axis labels
- Chart Piechart in only show percentage on hover but it shows data and label with percentage both i just want to show percentage only percentage
- ChartJS - Change legend to toggle buttons
- Creating chart.js chart directly to PNG in Node js?
- Chart.js drawing line between two points
- Missing Tooltip for some data points using chartjs
- Chart.js combine two pieces of data into one bar
- How do you plot scatter graph with chart.js
- Updating Chartjs Line chart from database
- Chartjs showing labels for bidimensional array
- Chart.js chart not displaying until I open the browser's console
- Ionic + Angular Charts: Uncaught Error: Chart.js library needs to included
- ChartJS changing graphs based upon Drop Down selection
- Vue chartjs is not rendering from API
- Vuejs parameters in props
- set background color to save canvas chart
- Customizing Chart.js troubleshoot
- Display multiple chart.js charts using for loop in Django template
- I am having this error in charts v3 chartjs-chart-treemap: fontColor does not exist in type 'ChartDataset<"treemap", TreemapDataPoint[]>