score:0
Accepted answer
The displayFormats option in time does not seem to have any influence regardless whyt I am typing there...
Because Chart.js has not been told to use the time
type axis, e.g.:
xAxes: [{
id: 'xAxis0',
type: "time", // <-- add this line.
time: {
...
Also, the for
loop in getHoursLabels
should use <
instead of <=
as otherwise it iterates past the end of the input array and appends NaN:NaN
to the result array.
Also, your displayFormats
can be simplified to:
displayFormats: {
hour: 'H'
}
Here's a fully working example:
var ctx = document.getElementById('myChart');
var HourLabels = [];
MinLables = [54, 83, 155, 192, 206, 238, 285, 307, 335, 367, 431, 444, 495, 548, 604, 651, 680, 721, 777, 789, 859, 936, 980, 1004, 1047, 1089, 1122, 1135, 1200, 1245, 1323, 1381, 1396]
function parseMinToHours(x) {
MINUTES = x;
var m = MINUTES % 60;
var h = (MINUTES - m) / 60;
var HHMM = h.toString() + ":" + (m < 10 ? "0" : "") + m.toString();
return HHMM;
};
function getHoursLabels() {
for (var i = 0; i < MinLables.length; i++) // not <=, only < !!!
HourLabels.push(parseMinToHours(MinLables[i]));
};
getHoursLabels();
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: HourLabels,
datasets: [{
label: "Messwert",
xAxisID: 'xAxis0',
data: [196.0, 222.0, 251.0, 272, 258, 298, 293, 235, 269, 226, 223, 242, 246, 290, 267, 261, 285, 274, 243, 200, 197, 203, 219, 269, 238, 268, 271, 280, 252, 266, 282, 296, 289, 300, 291],
lineTension: 0,
fill: false,
borderColor: 'orange',
backgroundColor: 'transparent',
borderDash: [5, 5],
pointBorderColor: 'orange',
pointBackgroundColor: 'rgba(255,150,0,0.5)',
pointRadius: 5,
pointHoverRadius: 10,
pointHitRadius: 30,
pointBorderWidth: 2,
pointStyle: 'rectRounded'
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
legend: {
display: true,
position: "left",
labels: {
fontColor: 'rgb(255, 99, 132)'
}
},
scales: {
xAxes: [{
id: 'xAxis0',
type: "time", // add this!
time: {
parser: 'H:m',
unit: 'hour',
stepSize: 1,
min: '00:00',
max: '23:59',
displayFormats: {
hour: 'H', // change to uppercase 'H'.
}
},
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js"></script>
<canvas id="myChart"></canvas>
Source: stackoverflow.com
Related Query
- chart.JS time axis labels should be just in hours format
- how to minimize x axis labels to day hours in chart js
- chart js - bar chart with time scale on Y axis in Hours and Minutes
- Time chart labels with some X axis labels using Chart js v3
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- Chart JS - set start of week for x axis time series
- time series stream, removing am/pm on x axis and 24 hour format
- Chart.js Dynamically Updating Chart with X Axis Time
- Changing x axis labels in Chart.js line chart
- Line chart with large number of labels on X axis
- Format Y axis of Chart.JS as Time
- How do I add time sourced from an external source as an X axis to a ChartJS graph?
- Display Time In Y Axis - Bubble Chart
- ChartJS shows date, but not time, when displaying labels in time axis
- chart.js: How do I make the radar chart axis labels bigger?
- How to plot chart from external JSON and format X-AXIS to show time using Chart.JS?
- Chartjs React Typescript moving x axis labels above chart
- Inverting X axis number labels in chart.js scatter chart
- 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
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- ChartJS/High Charts Radar chart - Different radial axis labels for each category that appear on hover
- Adding hours and minutes to a date object for time axis
- how to format date string for x axis labels in chartjs?
- How to use chart.js to plot line chart with x axis as time stamp in seconds
- How to change text colour of specific labels of axis in Chart JS?
- X and Y axis labels not displaying on line chart (Chart.js)
- X axis should have a space in Line chart- Chart JS
- ChartJs x axis labels on waterfall chart
- Chart.js bar chart with time on X axis and category on Y axis is not rendered
- ng2 scatter chart how to put labels in x axis
More Query from same tag
- How to change default label of each bubble in bubble chart using chartjs-plugin-datalabels
- Two independent time axes in Chart.js
- How can I add padding between tick labels?
- How to fetch data from Json file on charts(bar-chart/pie chart etc) in angular?
- Which jquery plugin can create a stacked column chart?
- Laravel & chartjs blank canvas
- "Type of import (".../charjs/types/indexsm" has no construct signatures issue on Vue3 and ChartJS?
- Y axis limit in Chart JS Bar chart?
- $scope variable not updating when factory object changes AngularJS
- How to update chart.js chart with new data?
- Data with x and y data, missing data are not taken into account
- Populating Chart.Js line graph with multiple lines using data from a JSON Object
- How to clear/destroy Chart.js canvas when the chart is represented as a react JSX element
- How to register plot or label click event in chart.js
- Using Variable in labels Chart.js of map Array
- How to change the labels to the image (icon) in bar chart.js
- Something similar to grace available in the latest chartJs for ChartJs 2.9.3
- Chartjs - Insert labels at xAxes
- Need Clarity on Chartjs - Asp.NetMVC or Vue-ChartJS -Asp.Net MVC
- Split assoc array by keys
- How can I append a calculated value to the end of a bar in Chart.JS?
- How can I update my ChartJS in real time (It's works only when I zoom-in and zoom-out)
- Prevent size of canvas chart js to equal window height and width
- chart.js, after each update, avoid scrolling to top position
- Chart.js different y axis depending on graph from select options
- How can I add multiple datasets into my dropdown menu and keep it as dynamic as it is right now?
- getting additional value fields from data source for dx.chartjs doughnut chart
- interactive Button doesn't hide the chart as I intended
- ChartJS adding shadow color to grid and custom x-axis labels
- Change <p> and <h> element when selecting something from dropdown