score:1
Accepted answer
This is because a scatter chart uses linear axis for the x axis by default and a line chart uses a category axis, these are not compatibale with each other so you will need to use a second X axis. Also your labels array is in the wrong place, it is supposed to be in the data
part of the config:
const labels1 = ['A', 'B', 'C', 'T', 'GW', 'RT', 'MJ', 'JY', 'YJ', 'TR', 'UY', 'IY', 'TR', 'RE', 'WE', 'WE', 'WE', 'BV', 'CS', 'EW'];
const data1 = {
labels: labels1, // place labels array in correct spot
datasets: [{
type: 'line',
label: 'Line Dataset',
data: [10, 10, 10, 10],
backgroundColor: 'rgb(0, 0, 255)',
borderColor: 'rgb(0, 0, 255)',
xAxisID: 'x2' // Specify to which axes to link
},
{
type: 'scatter',
backgroundColor: 'rgb(0, 0, 0)',
borderColor: 'rgb(255, 0, 0)',
data: [{
x: 1,
y: 36
}, {
x: 1,
y: 37
}, {
x: 1,
y: 40
}, {
x: 1,
y: 40
}]
}
],
}
const myChart = new Chart('chartJSContainer', {
type: 'scatter',
data: data1,
options: {
scales: {
x: {
min: 0,
max: 19,
ticks: {
stepSize: 1
}
},
x2: { // add extra axes
position: 'bottom',
type: 'category'
},
y: {
min: 0,
max: 120,
ticks: {
stepSize: 10
},
grid: {
display: false
}
},
}
}
});
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.6.2/chart.js"></script>
</body>
Source: stackoverflow.com
Related Query
- chart.js combine scatter and line
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Chart.js Mixed Bar and Line chart with different scales
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- Draw a horizontal and vertical line on mouse hover in chart js
- Can Chart.js combines Line Chart and Bar Chart in one canvas
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Can we draw a Line Chart with both solid and dotted line in it?
- ChartJS Line chart cut off at the top and bottom
- How to show data values in top of bar chart and line chart in chart.js 3
- ChartJS line chart drag and zoom
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- annotation line not visible in scatter chart in chartjs
- Chart.js Date and Time Bar Chart Not Rendering - Line Works Though
- How to change the label and grid line position on a timeseries chart in Chart.js 3?
- Dynamic line chart with chart.js and PHP
- How to sort XY line chart tooltip items based on value and add thousands separators?
- Chart.js Bar and Line chart
- how can i use chart.js to create a chart that has one time series line and one linear line on it at the same time?
- ChartJS, Primeng, Gap first and end of line chart
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- Can't Draw Horizontal Line on Graph Using ChartJS Annotation Plugin and Primevue Chart
- How do you set x and y axis and Title for a line chart using charts.js?
- Chartjs draw line chart where line go back and forth (by chronological order)
- Is there any way to remove extra space and Horizontal line from Bar chart of Chart.js?
- How do you set up a chart.js scatter line chart through angular-chart.js?
- Chart.js combined line and bar chart with differing data points
- X and Y axis labels not displaying on line chart (Chart.js)
- Draw line between starting point and Ending point in semi doughnut chart in chart js
More Query from same tag
- How can I show JSON data in Chart.js with Javascript if static values are working but dynamic from mySQL are not?
- ChartJS keeps resizing canvas to the default size
- chart.js hide gridline inside chartarea but keep y-axis border
- Deleting and recreating an element with React
- How to change the color of legend in chartjs and be able to add one more legend?
- ChartJs canvas showing previous graph when changing Graph types
- Chart Js Show the old data on mouse hover
- Custom data in label on ChartJS pie chart
- Setting Common labels and background color common for all the charts in ChartJs
- Ionic 3 Angular component load listener
- How to add unused data background to bar in chart js
- Php add dummy data to array
- How can I fasten up the Chart.js graph generation from JQuery over PHP and mySQL?
- Limit chart.js X axis ticks
- Add information on y Chart Js
- Getting chart.js to work with Django and Apache
- Pagination for Chart.js line chart?
- Can I interpret Django object values as JSON data within the JS script in my HTML?
- Chart.js not showing correctly/install issues
- Django and Chart.js Not Rendering Graph Correctly
- Multiple Chart JS percentage labels
- Chartjs doughnut with multiple dataset issue in legend creation
- how to dynamicly change the json data in chartjs
- Chart.js: Some sectors not showing if difference is too big
- Add HTML to label of bar chart - chart js
- How do I increase the space between the Legend and the Chart when using angular-chart.js?
- Chartjs cannot read property datasets of undefined
- ChartJS Line chart cut off at the top and bottom
- Parse a JSON object to ChartJS
- Angular4 ng2-charts TypeError: Cannot read property 'length' of undefined