score:2
Accepted answer
Here is the solution.
You need to add the ticks source to data.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- import chartjs -->
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.2.1" crossorigin="anonymous"></script>
<!-- import luxon for working with datetimes -->
<script src="https://cdn.jsdelivr.net/npm/luxon@1.26.0" crossorigin="anonymous"></script>
<!-- import luxon adpater for integration with chartjs -->
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-luxon@1.0.0/dist/chartjs-adapter-luxon.min.js" crossorigin="anonymous"></script>
</head>
<style type="text/css">
.chart {
width: 600px !important;
height: 600px !important;
}
</style>
<body>
<div class="chart"><canvas id="chartjs"></canvas></div>
<script type="text/javascript">
var ctx = document.getElementById("chartjs").getContext("2d");
// Datetimes to display on chart
let datetimes = [luxon.DateTime.utc(2000, 1, 1, 0, 5), luxon.DateTime.utc(2000, 1, 1, 4, 11), luxon.DateTime.utc(2000, 1, 1, 12, 38), luxon.DateTime.utc(2000, 1, 1, 15, 10), luxon.DateTime.utc(2000, 1, 1, 18, 41), luxon.DateTime.utc(2000, 1, 1, 22, 2)];
// Create an array of ISO strings
let datetimes_isos = [];
datetimes.forEach(function(item, index, array) {
datetimes_isos.push(item.toISO());
});
// Chart's data
let data = [{ x: datetimes_isos[0], y: 0 }, { x: datetimes_isos[1], y: 10 }, { x: datetimes_isos[2], y: 20 }, { x: datetimes_isos[3], y: 40 }, { x: datetimes_isos[4], y: 50 }, { x: datetimes_isos[5], y: 60 }];
const chartData = {
labels: datetimes_isos,
datasets: [{ data: data }]
};
const config = {
type: 'line',
data: chartData,
options: {
scales: {
x: {
type: 'time',
ticks:{
source:'data'
},
time: {
unit: "minute"
},
}
},
},
};
var theChart = new Chart(ctx, config);
</script>
</body>
</html>
Source: stackoverflow.com
Related Query
- In Chart.js >3.0, on axis of type time, how to show labels and ticks only for existing data points (make labels reflect data)?
- How to show tick marks and labels with grid line for the specific one on the X axis with Chart.js?
- Chart.js how to show cursor pointer for labels & legends in line chart
- How to show Y axis ticks for every point in the graph
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- How to show scale labels and set min/max for yAxes?
- How do I customize y-axis labels and randomly pick the value from the data range for x-axis in Chart js
- How to change fonts and axis labels for Chart.js image rendering with QuickChart?
- How to plot chart from external JSON and format X-AXIS to show time using Chart.JS?
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- How do you set x and y axis and Title for a line chart using charts.js?
- how can i show labels and value in both on bar chart
- How to start the chart from specific time and offest hour and then show the data on chart from target datetime in chartjs
- Chart.js how to show line chart without displaying the labels on xaxis and yaxis
- How remove duplicates xAxis labels and show all values on chart
- How to provide different labels in chart.js for toolbox and axis
- ChartJs line chart time cartesian axis number of ticks and wierd offset
- how to show X and Y labels on points in Chart js 2 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
- how to only show zero grid axes at center and hide all other gridlines in chart js
- How to set max and min value for Y axis
- Chart.js: only show labels on x-axis for data points
- show label in tooltip but not in x axis for chartjs line chart
- How to add second Y-axis for Bar and Line chart in Chart.js?
- Chart JS - set start of week for x axis time series
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- Chartjs: how to show only max and min values on y-axis
- Remove the label and show only value in tooltips of a bar chart
More Query from same tag
- chart.js change size of label of radar chart
- How to pass a variable to the dataset for a graph in chart.js?
- Create Line Chart and populate with database information
- Chart.js: Change lengend colors to array
- Connect the dot vertically instead of horizontally on Line Chart
- Chart.js Vertically Aligned points on single x axis
- Strange "padding" at chart area after updating chart.js (2.8.0 -> 3.4.1)
- updating a chart in chart.JS using a dropdown button
- No chart display for Chart.js and JSON data
- I want to hide the line as shown below
- Change font family of labels in piechart and linechart in chartjs
- Chart.js usage error (v2.4)
- How to change states for making dynamic pie chart?
- chart.js Is there way to color line chart ticks depending on value
- ChartJs events in Angular
- Charts.js Dynamic Ticks
- The bar that contains a low value is almost invisible on the chartjs
- ChartJS - Finding the minimum and maximum labels that are inside a pan (When zooming)
- Draw a line around a single point in the linechart
- How to use JSON data in creating a chart with chartjs?
- Chart.js how to increase segments size to be more evenly distributed
- Can I interpret Django object values as JSON data within the JS script in my HTML?
- dynamically fill a json variable
- angular chartjs line chart default options
- Chart.js 3.6.2, Angular 10: Logarithmic Line chart Y-Axis problems. How to set and keep Y-Axis properties, even when data changes?
- Make chartjs pie chart wiyh dynamic data
- How to change chart.js grid, and axis color?
- Align Chart JS Y-Axis dot with X-Axis value
- Is it possible to add image behind doughnut chart with transparency color in ng2chart?
- charts.js chart size it's diferente than container setted size