score:9
On your html:
<canvas id="myChart" width"600" height:"600"></canvas>
It should be:
<canvas id="myChart" width="600" height="600"></canvas>
Then, Replace your code
var c = $('#myChart');
var ct = c.get(0).getContext('2d');
var ctx = document.getElementById("myChart").getContext("2d").Line(data);
With this code
var ctx = new Chart(document.getElementById("myChart").getContext("2d")).Line(data);
So in your js
var data = {
//your data here
}
enter code here
and then add this line after your data
var ctx = new Chart(document.getElementById("myChart").getContext("2d")).Line(data);
So your code would look like this:
var data = {
labels: ["January", "February", "March", "April", "May", "June", "July","August", "November", "December"],
datasets: [
{
label: "Sodium intake",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [165, 159, 180, 181, 156, 155, 140]
},
{
label: "Sugar intake",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [128, 148, 140, 119, 186, 127, 190]
}
]
}
var ctx = new Chart(document.getElementById("myChart").getContext("2d")).Line(data);
score:0
The reason may be that you are using the latest chart.min.js but using the old code. For correct reference, follow the chartjs.org documentation.
The code configuration structure has changed in the latest release. (I guess from 2.3 onwards)
So, instead of
var countries= document.getElementById("countries").getContext("2d");
var chart = new Chart(countries).Pie(pieData,pieOptions);
We are structuring like:
var countries= document.getElementById("countries").getContext("2d");
var chart = new Chart(countries,{
type: 'pie',
data:
{
labels: ['India', 'Germany', 'Netherland'],
datasets:
[{
backgroundColor: '#337ab7',
data: ['100', '99' ,'98'],
borderWidth:1,
}]
},
options:
{
responsive: true,
maintainAspectRatio:false,
legend: {
display: false,
position: 'top'
}
}
});
or
var countries= document.getElementById("countries").getContext("2d");
var pieData =
{
labels: ['India', 'Germany', 'Netherland'],
datasets: [{
backgroundColor: '#337ab7',
data: ['100', '99' ,'98'],
borderWidth:1,
}]
};
var pieOptions =
{
responsive: true,
maintainAspectRatio:false,
legend: {
display: false,
position: 'top'
}
};
var chart = new Chart(countries,{
type: 'pie',
data: pieData,
options: pieOptions
});
score:2
Ok, try this :
for a start correct your html :
<canvas id="myChart" width="600" height="600"></canvas>
then try this for your javascript :
var data = {
"labels": ["January", "February", "March", "April", "May", "June", "July", "August", "November", "December"],
"datasets": [{
label: "Sodium intake",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [165, 159, 180, 181, 156, 155, 140]
}, {
label: "Sugar intake",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [128, 148, 140, 119, 186, 127, 190]
}]
}
var chartDisplay = new Chart(document.getElementById("myChart").getContext("2d")).Line(data);
And that should do ok. See a jsfiddle of it.
Source: stackoverflow.com
Related Query
- Chart.js line chart is not displaying
- Stacked line chart not displaying correctly when Xaxis is time
- Legend not displaying on Line or Bar chart - React-Chartjs-2
- X and Y axis labels not displaying on line chart (Chart.js)
- Data not displaying properly in Chart.js line chart
- Why is my Line Chart not displaying (Chart.JS)?
- Chart.js: bar chart first bar and last bar not displaying in full
- show label in tooltip but not in x axis for chartjs line chart
- Angular-chart.js - Make line chart does not curve
- angular-chartjs line chart TypeError: t.merge is not a function
- Line chart is not being displayed in Chart.js
- Time series line chart is not displayed
- Time Series Line chart js in react not working
- Angular: chart.js chart is not displaying
- Chart not displaying from JSON data
- Click event of stacked line chart not working
- ChartJS "half donut" chart not displaying properly
- Chart.js tooltip not showing on line chart
- annotation line not visible in scatter chart in chartjs
- Chart.js Date and Time Bar Chart Not Rendering - Line Works Though
- Displaying line chart for multiple months using chart.js
- Vertical Bar Chart not displaying Correctly
- Doughnut Chart not displaying data with Chart Js and Backbone js
- Want only line not area under it in chart js
- Do not draw line on condition in ChartJS line chart
- Chartjs Stacked bar chart not displaying correctly
- Chart with Time axis only displaying first grid line and tick label (unitStepSize)
- vertical grid line not taking full hight of the canvas in chart js 3.3.2
- Line Chart is not setting backgroundColor when created dynamically Chart.js
- ChartJS graph not displaying - line graph
More Query from same tag
- chart.js zeroLineColor does not work as expected
- Angular ChartJs colors option not working
- ChartJS linechart edit yAxis labels
- Adding Chart.js line chart to Jinja2/Flask html page from JS file
- ChartJS tooltip when having multiple lines on a time graph
- How to remove the unnecessary overlaying gridlines using Chart.js?
- Chart.js 2 - Always display only some tooltips in bubble chart
- Chart.js multiTooltip Labels in Pie
- Hide label on slice of Doghnut/Pie Chart Angular ng2-charts
- Multiple Chart.js Charts in Partial Views Overwriting Each Other
- Chartjs create chart with big data and fixed labels
- Chart.js data values from textbox input only load once
- How can I get my Chart.JS bar chart to stack two data values together on each bar, and print a calculated value on each bar?
- Change axes position in line chart
- Wrong label value is displayed on point hover - Chart.JS
- Why does one chart overlays another (chart.js)?
- How to set ChartJS animation speed?
- How to align Chart.JS line chart labels to the center
- Chart.js axes always show zero
- How to make customized stepSize for each horizontal bar in Chart.js graph
- Customizing Chart.js
- Proper way to use a counter variable in HTML/Javascript
- Rendering charts using local Chart.js in overriding Django templates
- angular-chart.js custom color based on chart label values
- Center point labels between ticks (Polar Area Chart JS)
- Chart.js not showing value on top of bars
- How to Render Chart Datasets in Vue?
- Add \n or line break on chart.js (pie chart) labels
- How do I obtain a Chart instance for Chart.js
- Implement ng2-charts in an Angular-Seed