score:2
Accepted answer
you are trying to use v2 and v3 config at the same time, this wont work. you need to remove the array format and only use the objects to define scales.
when placing the min and max props at the root of the x object for the x scale it works fine, although the time between the min and max you are using is only 1,5 minute:
// setup block
const data = {
datasets: [{
label: 'sales',
data: [{
x: '2021-08-08t13:12:23',
y: 3
},
{
x: '2021-08-08t13:12:45',
y: 5
},
{
x: '2021-08-08t13:12:46',
y: 6
},
{
x: '2021-08-08t13:13:11',
y: 3
},
{
x: '2021-08-08t13:14:23',
y: 9
},
{
x: '2021-08-08t13:16:45',
y: 1
}
],
bordercolor: 'rgba(234,124,234,0.4)',
backgroundcolor: 'rgba(34,14,24,0.4)'
}]
};
// config block
const config = {
type: 'line',
data,
options: {
scales: {
x: {
type: 'time',
time: {
unit: 'second'
},
min: '2021-08-08t00:00:00',
max: '2021-08-08t23:59:59'
},
y: {
beginatzero: true
}
}
}
};
// render / init block
const mychart = new chart(
document.getelementbyid('mychart'),
config
);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>document</title>
<link rel="stylesheet" href="main.css">
</head>
<body>
<div class="chart-container">
<canvas id="mychart"></canvas>
</div>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>
<script src="my-chart.js"></script>
</body>
</html>
Source: stackoverflow.com
Related Query
- How to set the xAxes min and max values of time cartesian chart in Chart.js
- How to set only min and max values in y-axis (chart js)
- How to set max and min value for Y axis
- ChartJS: How to set fixed Y axis max and min
- Chart.js timescale: set min and max on xAxes
- Chartjs: how to show only max and min values on y-axis
- How can I display the xAxes and yAxes data in the tooltip, Chart JS?
- How can I have different values for the chart and the tooltip in chart.js?
- 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?
- How to take a set of Date objects and display the frequency based on time of day using ChartJS
- How to set min max for x axis depend on data with Chartjs and Spring Boot?
- Chart.js How to sum the values in a pie chart and display them in the header
- chart.js how to force min and max y axis values
- How to start the chart from specific time and offest hour and then show the data on chart from target datetime in chartjs
- how to change the label color and set y-axis values 1k intervals and hide y-axis?
- How to set the data of chart in angular which is taken from the backend nodejs api that is store in mongodb and showing on the html page
- Hide min and max values from y Axis in Chart.js
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- Chart js: how can I align the legend and the title
- How to get the actual chart width and height in chart.js
- How to show data values in top of bar chart and line chart in chart.js 3
- How to draw a needle on a custom donut chart and add datapoints to the needle?
- How can I datalabels and Sum display in the same time on a stacked bar
- How do I force Chart.js axes min and max with react-chartjs-2?
- How to commaize the data values provided to a chart in Chart.JS?
- How to create a chart that uses strings for both the X and Y axes?
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- How to change the label and grid line position on a timeseries chart in Chart.js 3?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
More Query from same tag
- Chartjs time serie in wrong format
- ChartJS on small screen
- Use PHP to populate chart.js with data from an SQLite Database
- How to use Chart.js to draw mixed Financial / Candlestick and Bar Chart?
- Chart.js tooltip not showing on line chart
- How do i make a new chart by pressing a button (chart.js)?
- Time scale formatting issues with chartjs, mostly unitStepSize
- ChartJS fails to render one of the lines in cartesian chart following update after change to max Y axis label value
- Overlay Line on chart.js Graph
- Chart.js Y axis label, reverse tooltip order, shorten X axis labels
- Parsing error: Unexpected token, expected ";" line 54 in .map function
- Chart js x-axis values getting repeated twice
- Custom data in label on ChartJS pie chart
- How to generate PDF with Chart.js
- In a Stacked Line Chart, is there a way to stack multiple Y-Axes to match each graphed line?
- Chart.js: colouring tooltip labels
- How to make bar chart animation where all bars grow at the same speed?
- ChartJS set yAxes "ticks"
- Remove additional white space on left and right side of Angular Chart
- Chartjs: display value in html element when hovering a bar
- Customizing Chart.js troubleshoot
- chartjs datalabels not showing anything with django template
- Chart.js charts not rendering data until I inspect element, is it because of async?
- how to set a custom tick format in chartjs options from laravel controller?
- How to use major tick marks in chart.js 2.9.3?
- Accessing data from the callback function of a bar chart using chart js
- Hiding the ticks on the x-axes clips the chart (Chart.JS)
- Angular2 + Chart.js and ng2-charts. Data binding not working as expected
- How can I debug maxTicksLimits in charts.js?
- How can I make my backgroundColor in Chart.js match up with a reversed order y axis?