score:0
Accepted answer
you forgot to define data.labels
data: {
labels: labels,
...
further the chart options
were nested inside the second dataset
. please have a look at the corrected code below.
function buildchart(labels, valuesa, valuesb, charttitle) {
var ctx = document.getelementbyid("mychart").getcontext('2d');
var mychart = new chart(ctx, {
type: 'line',
data: {
labels: labels,
datasets: [{
label: 'temperature',
fill: false,
data: valuesa,
backgroundcolor: 'red',
bordercolor: 'red'
}, {
label: 'relative humidity',
fill: false,
data: valuesb,
backgroundcolor: 'blue',
bordercolor: 'blue'
}]
},
options: {
responsive: true,
maintainaspectratio: false,
scales: {
xaxes: [{
ticks: {
beginatzero: true,
scalelabel: {
display: false,
labelstring: ''
}
}
}],
yaxes: [{
scalelabel: {
display: false,
labelstring: ''
}
}]
}
}
})
return mychart;
};
var xhttp = new xmlhttprequest();
xhttp.onreadystatechange = function() {
if (this.readystate == 4 && this.status == 200) {
var json = json.parse(this.response);
// map json labels back to values array
var labels = json.feed.entry.map(function(e) {
return e.gsx$tag.$t;
});
// map json values back to values array
var valuesa = json.feed.entry.map(function(e) {
return e.gsx$dailytemperature.$t
});
// map json values back to values array
var valuesb = json.feed.entry.map(function(e) {
return e.gsx$dailyrh.$t
});
buildchart(labels, valuesa, valuesb, "temperature", "relative humidity");
}
};
xhttp.open("get", "https://spreadsheets.google.com/feeds/list/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/x/public/full?alt=json", false);
xhttp.send();
<script src="https://cdnjs.cloudflare.com/ajax/libs/chart.js/2.9.3/chart.bundle.js"></script>
<canvas id="mychart""></canvas>
Source: stackoverflow.com
Related Query
- Multiple axis line chart with Chart.js and JSON data from Google Sheet
- ChartJS (React) Line Chart - How to show single tooltip with data and labels from 3 (multiple) dataset?
- Populating Chart.Js line graph with multiple lines using data from a JSON Object
- Line chart plotting multiple points for duplicate data on x and y axis using chart.js
- Chartjs 2 - Stacked bar and unstacked line on same chart with same y axis
- Show X axis on top and bottom in line chart rendered with Chart.js 2.4.0
- Multiple lines / data series from JSON file with Chart.js
- How to get chart from data points (arrays) with inconsistent time intervals and chart.js?
- react-chartjs-2 line chart with time on X-axes with multiple data sets plotted wrong
- Drawing line chart in chart.js with json data
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- Chart.js combined line and bar chart with differing data points
- Google Charts, HighCharts or ChartJS Dual Axis Gantt Chart and Line Chart Visualization
- Plotting multiple JSON subobjects in Chart.js Line chart ( with Time as x-axis)
- how to add multiple data in chart js dynamically from JSON
- How to use computed property with data from JSON in data object for time axis in Vue using Chart.js
- Html5 web page with chartjs: loading an external json file and create a line chart
- Getting charts.js to read from Google Sheet JSON data
- Add data to line chart js dynamically with multiple lines
- Chartjs random colors for each part of pie chart with data dynamically from database
- line chart with {x, y} point data displays only 2 values
- Chart.js Mixed Bar and Line chart with different scales
- Obtain max value of y axis of line chart rendered with Chart.js
- Line chart with large number of labels on X axis
- How to hide the y axis and x axis line and label in my bar chart for chart.js
- ChartJs line chart - display permanent icon above some data points with text on hover
- Drawing line chart in chart.js with json response
- Chart.js with dual axis on bar and line graph
- Can we draw a Line Chart with both solid and dotted line in it?
- How to start the line graph from the left Y axis in a line/bar mixed chart (Chart.js)?
More Query from same tag
- How to create an angular 7 component?
- start y-axis from 0 in ng2-charts
- Multiple lines / data series from JSON file with Chart.js
- Chart.js line chart does not render data lines on iOS
- Load ChartJS via VueJS - ChartJS empty and 0px dimension
- Data not fully displaying on bar chart
- JSON cyclic object value when posting data in ChartJS
- ChartJs: X Axis labels cutting at bottom
- How to plot a single value with line in line chart graph using charts.js?
- Chartjs gradient background color based on min and max values
- onHover event is not triggering in chart.js
- ChartJS does not display the legend
- Chart JS - How to output JSON objects into PIE variant
- Place tooltip on the outer side of the doughnut chart
- I have a chart but it is not updating the chart with react chart-js-2
- How to get rid of axis lines in ChartJS?
- JQuery Line Chart's X Axis not display in ASP.NET, C#, SQL Server
- Chart.js with handlebar.js shows empty canvas
- Array value is not being passed to the plugin
- Add buffer to Y axis with chart js
- interactive Button doesn't hide the chart as I intended
- How do I hide line outside the min/max (scale area) in chartjs 2.0?
- Trying to get _index of clicked bar in ChartJS
- Javascript instead of mapping to an array, returning one value at a time instead of a list of data?
- Having problems getting a line chart in Chartsjs to go *up* to 1, with bkg fill *under* the chart line
- Getting the postion of the y-axis labels in chartJS
- Display API data in line charts dynamically
- Trigger axispointer function on existing chart js via console
- Best way to connect Django Query results to Chart.js charts?
- how do I break a comma separated string into new lines in tooltip callbacks afterBody?