score:0
Accepted answer
the time scale by default generates nice
ticks because time can be verry far appart. if you want to show all the ticks you will need to set the source
in the ticks to 'data'
. after that the autoskip property will work.
scales: {
y: {
type: 'time',
ticks: {
source: 'data',
autoskip: false
}
}
}
live example:
// setup
const data = {
datasets: [{
label: 'pz-1',
data: [{
y: '2022-02-25',
x: 40.551
}, {
y: '2022-03-01',
x: 35.889
}, {
y: '2022-03-02',
x: 34.68
}, {
y: '2022-03-03',
x: 33.182
}, {
y: '2022-03-04',
x: 30.82
}, {
y: '2022-03-05',
x: 29.864
}, {
y: '2022-03-08',
x: 28.413
}, {
y: '2022-03-10',
x: 28.413
}, {
y: '2022-03-12',
x: 28.424
}, {
y: '2022-03-15',
x: 25.578
}, {
y: '2022-03-17',
x: 27.07
}, {
y: '2022-03-19',
x: 27.42
}, {
y: '2022-03-22',
x: 27.478
}, {
y: '2022-03-24',
x: 22.817
}, {
y: '2022-03-26',
x: 22.576
}, {
y: '2022-03-29',
x: 22.326
}, {
y: '2022-03-31',
x: 22.011
}, {
y: '2022-04-02',
x: 21.672
}, {
y: '2022-04-05',
x: 21.561
}, {
y: '2022-04-07',
x: 21.307
}, {
y: '2022-04-09',
x: 34.988
}, {
y: '2022-04-12',
x: 28.89
}, {
y: '2022-04-14',
x: 28.618
}, {
y: '2022-04-17',
x: 28.862
}, {
y: '2022-04-19',
x: 27.727
}, {
y: '2022-04-21',
x: 27.493
}, {
y: '2022-04-23',
x: 27.149
}, {
y: '2022-04-26',
x: 25.862
}, {
y: '2022-04-28',
x: 25.59
}, {
y: '2022-04-30',
x: 25.37
}, {
y: '2022-05-04',
x: 24.79
}, {
y: '2022-05-06',
x: 24.927
}],
backgroundcolor: '#ffd700',
bordercolor: '#ffd700',
borderwidth: 1
}]
};
// config
const config = {
type: 'line',
data,
options: {
indexaxis: 'y',
scales: {
x: {
beginatzero: true
},
y: {
reverse: true,
type: 'time',
ticks: {
autoskip: false,
source: 'data'
}
}
}
}
};
// render init block
const mychart = new chart(
document.getelementbyid('mychart'),
config
);
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.chartcard {
width: 100vw;
height: 100vh;
background: rgba(255, 26, 104, 0.2);
display: flex;
align-items: center;
justify-content: center;
}
.chartbox {
width: 1200px;
padding: 50px;
border-radius: 20px;
border: solid 3px rgba(255, 26, 104, 1);
background: white;
}
@media only screen and (min-width: 1600px) {
.chartbox {
width: 1600px;
}
}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>line chart</title>
</head>
<body>
<div class="chartcard">
<div class="chartbox">
<canvas id="mychart" style="position: relative;"></canvas>
</div>
</div>
<script src="https://rawgit.com/moment/moment/2.2.1/min/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.7.1/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
score:-1
you must set a height, otherwise it will adjust to the height available and show only some y-data.
// setup
const data = {
datasets: [
{label: 'pz-1',data:[{y:'2022-02-25', x:40.551},{y:'2022-03-01', x:35.889},{y:'2022-03-02', x:34.68},{y:'2022-03-03', x:33.182},{y:'2022-03-04', x:30.82},{y:'2022-03-05', x:29.864},{y:'2022-03-08', x:28.413},{y:'2022-03-10', x:28.413},{y:'2022-03-12', x:28.424},{y:'2022-03-15', x:25.578},{y:'2022-03-17', x:27.07},{y:'2022-03-19', x:27.42},{y:'2022-03-22', x:27.478},{y:'2022-03-24', x:22.817},{y:'2022-03-26', x:22.576},{y:'2022-03-29', x:22.326},{y:'2022-03-31', x:22.011},{y:'2022-04-02', x:21.672},{y:'2022-04-05', x:21.561},{y:'2022-04-07', x:21.307},{y:'2022-04-09', x:34.988},{y:'2022-04-12', x:28.89},{y:'2022-04-14', x:28.618},{y:'2022-04-17', x:28.862},{y:'2022-04-19', x:27.727},{y:'2022-04-21', x:27.493},{y:'2022-04-23', x:27.149},{y:'2022-04-26', x:25.862},{y:'2022-04-28', x:25.59},{y:'2022-04-30', x:25.37},{y:'2022-05-04', x:24.79},{y:'2022-05-06', x:24.927}],backgroundcolor: '#ffd700',bordercolor: '#ffd700',borderwidth: 1}
]
};
// config
const config = {
type: 'line',
data,
options: {
indexaxis: 'y',
maintainaspectratio: false,
responsive: true,
scales: {
x: {
beginatzero: true
},
y:{
reverse: true,
type: 'time',
ticks: {
autoskip: false
}
}
}
}
};
// render init block
const mychart = new chart(
document.getelementbyid('mychart'),
config
);
* {
margin: 0;
padding: 0;
font-family: sans-serif;
}
.chartcard {
overflow:auto;
background: rgba(255, 26, 104, 0.2);
display: flex;
align-items: center;
justify-content: center;
}
.chartbox {
padding: 50px;
border-radius: 20px;
border: solid 3px rgba(255, 26, 104, 1);
background: white;
}
@media only screen and (min-width: 1600px) {.chartbox {width: 1600px; }}
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>f3 peizometer</title>
</head>
<body>
<div class="chartcard">
<div class="chartbox">
<canvas id="mychart" style="position: relative;height:900px;width:400px"></canvas>
</div>
</div>
<script src="https://rawgit.com/moment/moment/2.2.1/min/moment.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/3.7.1/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
Source: stackoverflow.com
Related Query
- ChartJS autoskip:False not working on line chart
- show label in tooltip but not in x axis for chartjs line chart
- Time Series Line chart js in react not working
- Click event of stacked line chart not working
- ChartJS - radar chart options not working
- Bubble Chart in Chartjs not working
- annotation line not visible in scatter chart in chartjs
- Chartjs not working with d3 from csv source
- Do not draw line on condition in ChartJS line chart
- Bootstrap modal not working with chartjs line graph
- Background color of the chart area in chartjs not working
- Chartjs with Vue, Bar Chart Border Radius not working
- Legend color not working with randomly generated background colors in chartjs pie chart
- ChartJS line chart x = y not rendering astraight line
- Chartjs backgroundColor for line chart does not appear in Vue app
- Tooltip callbacks in line chart JS not working
- chartjs line graph destroy function is not clearing the old chart instances
- chartJS line chart not plotting values that are less than minY
- updating chartjs pie chart by using .keypress() not working
- angular chart js type line setting chart-options not working
- ChartJS Line Chart shoud not start at 0 with all Lines
- ReferenceError: Chart is not defined - chartjs
- Display line chart with connected dots using chartJS
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- chartjs show dot point on hover over line chart
- ChartJs line chart repaint glitch while hovering over
- Angular-chart.js - Make line chart does not curve
- ChartJS - Line Chart with different size datasets
- Show data dynamically in line chart - ChartJS
- angular-chartjs line chart TypeError: t.merge is not a function
More Query from same tag
- How to set a locale for Chart.js date labels?
- Why i lost my chart.js when i do a new render
- How to get access to Chart instance related to current tooltip callback in Chart.js
- Programmatically creating labels for Chart.js in angular?
- Append suffix to Chart.js dataset?
- Error Message when using ChartJS with React
- Checkboxes unchecked after cart.js end of update animation
- ChartJS: chart not show all data
- polarArea Chart.js starting from zero
- ChartJS Bar Graph Gap
- How to add several labels to the same set of data in chartjs?
- How to add "shadow" on hovering bar chart?
- Show/Hide data from Barchart with Chart.js
- Chart.js - Plot line graph with X , Y coordinates
- Chart.js Radial axes: is it possible to use multiple axes on radar chart?
- ChartJS - Help me custom tooltip
- How can I reduce the spacing between my legend and chart proper in my Chart.JS bar chart, and increase it in the graph area?
- Conditional in ChartJS axes tick callback function isn't returning the expected labels
- How to show thousand in k format for bar values in chart.js
- Create a pie chart using an array from a data table in chart.js
- Chart.js Auto Fit Failing
- Chartjs, scatter with For-Loop
- my anchor tags are not working in my website after i added chart.js in it
- Charts flickering
- Chart.js data background color is overwriting point background color
- how to add simple option to chartjs correctly
- How to reduce the number of data points displayed in react-chart-js2 (data decimation)
- Chart.JS Chart Not Being Generated
- Chart.js Text color
- How does chart updating works within the context of react?