score:2
as you can see in the following snippet and thanks also to Daniel W Strimpel for creating the initial snippet, you problem is in the hot and cold temperature data
.
{ x: new Date(2019, 0, 1, 14, 1, 19, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 20, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 21, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 22, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 23, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 24, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 25, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 26, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 27, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 28, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 29, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 30, 0) }
both of those arrays have n
number of entries in the end missing the y
coordinate including the temperature value. I recreated your scenario by deleting the y
for the 5 last entries of the cold and hot temperatures data
.
The chart
will add the date to the x axis
, but it will not add a temperature
value and the line will not show up.
{x: new Data(2019, 0, 14, 1, 26, 0) }
The code snippet recreates your scenario, you can run it to understand the problem and fix it by adding the y
value to the last 5 entries in the getHotTempData
and getColdTempData
var ctx = document.getElementById('tempChart').getContext('2d');
ctx.canvas.width = 320;
ctx.canvas.height = 240;
var chart = new Chart(ctx, {
type: 'line',
data: {
labels: [],
legend: {
display: true
},
datasets: [{
fill: false,
data: getHotTempData(),
label: 'Hot Temperature',
backgroundColor: "#FF2D00",
borderColor: "#FF2D00",
type: 'line',
pointRadius: 1,
lineTension: 2,
borderWidth: 2
},
{
fill: false,
data: getColdTempData(),
label: 'Cold Temperature',
backgroundColor: "#0027FF",
borderColor: "#0027FF",
type: 'line',
pointRadius: 1,
lineTension: 2,
borderWidth: 2
}]
},
options: {
animation: false,
responsive: true,
scales: {
xAxes: [{
scaleLabel: {
display: true,
labelString: 'Time ( UTC )'
},
type: 'time',
time: {
tooltipFormat: "hh:mm:ss",
displayFormats: {
hour: 'MMM D, hh:mm:ss'
}
},
ticks: {
maxRotation: 90,
minRotation: 90
}
}],
yAxes: [{
scaleLabel: {
display: true,
labelString: 'Temperature ( Celcius )'
},
}]
}
}
});
function getHotTempData() {
return [
{ x: new Date(2019, 0, 1, 14, 1, 19, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 20, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 21, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 22, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 23, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 24, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 25, 0), y: Math.random() * 0.5 + 35 },
{ x: new Date(2019, 0, 1, 14, 1, 26, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 27, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 28, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 29, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 30, 0) }
];
}
function getColdTempData() {
return [
{ x: new Date(2019, 0, 1, 14, 1, 19, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 20, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 21, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 22, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 23, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 24, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 25, 0), y: Math.random() * 0.5 + 23.5 },
{ x: new Date(2019, 0, 1, 14, 1, 26, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 27, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 28, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 29, 0) },
{ x: new Date(2019, 0, 1, 14, 1, 30, 0) }
];
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment-with-locales.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
<canvas id="tempChart"></canvas>
Source: stackoverflow.com
Related Query
- Chart.js Dynamically Updating Chart with X Axis Time
- chart js - bar chart with time scale on Y axis in Hours and Minutes
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- How to use chart.js to plot line chart with x axis as time stamp in seconds
- Time chart labels with some X axis labels using Chart js v3
- Chart.js bar chart with time on X axis and category on Y axis is not rendered
- Dynamically updating time data in chart.js freezes the chart
- hereChartJS Line Chart with Time Axis
- Update a chart dynamically with socket.io in real time
- Chart for Real time data with duplicate x axis
- Chartjs random colors for each part of pie chart with data dynamically from database
- ChartJS New Lines '\n' in X axis Labels or Displaying More Information Around Chart or Tooltip with ChartJS V2
- How to prevent first/last bars from being cut off in a chart with time scale
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- 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
- Obtain max value of y axis of line chart rendered with Chart.js
- Line chart with large number of labels on X axis
- Dynamically created Chart.js chart overpopulating time based x-axis?
- Add buffer to Y axis with chart js
- 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
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- Chartjs 3.x - How to duplicate X axis on both sides of horizontal bar chart with only 1 dataset?
- Line chart doesn't work with type time chart.js
- react-chartjs-2 line chart with time on X-axes with multiple data sets plotted wrong
- Updating chart.js chart with dataset of different size
- how to label axis within radar chart with chart.js
- How do you make a progressive line chart with time as the X axis?
- Chart isn't updating with Response data (Chart.js 3.2.1, ng2-charts 3.0.0-beta.9)
More Query from same tag
- Chart JS - single lines (points) tooltips
- Tooltip callbacks in line chart JS not working
- Grouping by month with series of epoch timestamps in Chart.js
- Chart.js - Writing Labels Inside of Horizontal Bars?
- Draw Line Chart Using Chart.js
- chartjs is issue with large amount data
- JavaScript Chart.js - Custom data formatting to display on tooltip
- Charts in Angular js with JSON Object
- Chart.js remove gridline
- Chart js how to remove numbers on circles of polar chart
- How can I display fixed labels on X-axis while having data on that axis?
- chart.js - Pie Chart doesn't display all data
- How to convert an array of strings to float in Javascript
- How to set min Value a step down of min value received from database in Y Axis in ChartJS
- Construct a bar chart using chart.js
- Convert SQLite PHP array into Javascript array?
- Set height of chart in Chart.js
- Cannot access a variable declared outside a For loop (Javascript)
- Changing Legend Label Position in VueChartjs
- Chart.js responsive pie chart
- Can't make chart with Chart.js
- Plotting multiple lines (line chart) in Apache Zeppelin using AngularJS
- ChartJS re-rendering bug
- Chart.js render in hidden Bootsrap tab
- How to draw horizontal Lines using chart.js 3.x ? Cannot get it working
- Chart.js -> line chart -> multiple points with the same X
- Adding condition in ComponentDidMount to display chart data
- Chart.js: bad alignment of label during ajax update
- How to change the label color in chart.js?
- Is there a way to add html markup to target each column individually in Chartjs/Canvasjs?