score:2
You can use a time axis:
const options = {
type: 'line',
data: {
labels: ["Fri Feb 11 2022 00:59:07 GMT+0530 (Indian Standard Time)", "Fri Feb 11 2022 00:59:17 GMT+0530 (Indian Standard Time)", "Fri Feb 11 2022 00:59:27 GMT+0530 (Indian Standard Time)"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3],
}]
},
options: {
scales: {
x: {
type: 'time'
}
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@^2"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-moment@^1"></script>
</body>
or you can use a custom tick callback to achieve this
const options = {
type: 'line',
data: {
labels: ["Fri Feb 11 2022 00:59:07 GMT+0530 (Indian Standard Time)", "Fri Feb 11 2022 00:59:17 GMT+0530 (Indian Standard Time)", "Fri Feb 11 2022 00:59:27 GMT+0530 (Indian Standard Time)"],
datasets: [{
label: '# of Votes',
data: [12, 19, 3],
}]
},
options: {
scales: {
x: {
ticks: {
callback: function(val) {
return this.getLabelForValue(val).substring(16, 24);
}
}
}
}
}
}
const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
</body>
Documentation: https://www.chartjs.org/docs/master/axes/labelling.html#creating-custom-tick-formats
Source: stackoverflow.com
Related Query
- How to plot chart from external JSON and format X-AXIS to show time using Chart.JS?
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- 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 use computed property with data from JSON in data object for time axis in Vue using Chart.js
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- How to export a chart in Excel and PDF format using Chart.js
- I am using chart.js I sent my time values throw my api as timestamp know i need to show them in the chart as date format
- How do you set x and y axis and Title for a line chart using charts.js?
- How to use chart.js to plot line chart with x axis as time stamp in seconds
- How to plot a line chart which has both the start and points outside the canvas area using Chart.js
- How to show symbols after the label and before the numeric value using chart.js Bar chart in Angular
- I am using chart js to draw a chart. I did everything right but i don't know why the x axis and y axis label is not comming in chart. code below
- Multiple axis line chart with Chart.js and JSON data from Google Sheet
- How to take data from an API and create a chart on that using Chart.js and Angular 8?
- How to prevent first/last bars from being cut off in a chart with time scale
- How to save Chart JS charts as image without black background using blobs and filesaver?
- time series stream, removing am/pm on x axis and 24 hour format
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
- How to show data values in top of bar chart and line chart in chart.js 3
- How to create a gantt chart using Chart.js and populate dates?
- How to show percentage (%) using chartjs-plugin-labels ( Pie chart ) in angular 2/8
- Using chart js version 3, how to add custom data to external tooltip?
- How to draw outer labels for polar chart using ng2-charts and chart.js at fixed positions outside the rings?
- 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)?
- Grouped Bar Chart from mySQL database using ChartJS and PHP
- How to make aspecific API call from within a Line Chart class in ReactJS using react-chartjs-2?
- How to Remove axis Lines from chart in chart js
More Query from same tag
- Javascript 2D array getting each element
- How to disable event during a state change
- Chart.js: Combined Line and Bar Data
- react-chartjs state update error
- ChartJs(Java) Can I remove only specific gridLines for a Linear Chart withouth removing the labels on xAxis?
- Chartjs ignore values and draw chart
- How to implement chart.js in Django?
- Custom Legend with ChartJS v2.0
- Second yAxes values not charting correctly with Chart.js
- Getting the postion of the y-axis labels in chartJS
- How to make a step line with charts.JS
- Visual Studio 2013 IIS web site - problems with JS files
- Assigning data structures to chartjs properties, NOT individually
- Chart.js Doughnut chart inner label different than outer
- place images over pie chart slices using chartjs
- How can i iterate or get all object out of array with object key in Chart.js
- How to create chart.js vertical bar chat with rounded corners in angular 6?
- Chart.js pie chart in table shows weird behavior on page resize
- How use my data with Charts.js in my case?
- Charts not rendering properly in Angular
- How to make bar chart cover multiple labels?
- ChartJS width undefined in React Typescript
- Adding chartjs-plugin-datalabels to Chart.js in Aurelia
- Making my website interactive with the size of the screen/browser
- Custom gridLines and Axes Chartjs
- Chartjs tick color different at zero
- How do I use ChartJS with a background color in the space between two line charts?
- Set minimum number of steps in line chart
- How to split data from api to get a chart
- Problems displaying yLabels in charts.js