TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Shiv Kumar Yadav
NA
269
25.8k
Chart using jquery Chart.js
Jan 16 2018 7:22 AM
Hi,
I am using chart.js for creating chart in asp.net whit the help of ajax method i am got value through ajax.
i have tried everything but it can not create chart can any one help me
this my code in jquery
$(document).ready(
function
() {
var
lbl = [];
var
dat = [];
$.ajax({
url:
"../Home/getData"
,
type:
"Post"
,
dataType:
"json"
,
success:
function
(data) {
$.each(data,
function
(key, value) {
lbl.push(value.Item);
dat.push(value.Price);
//alert("Item" + lbl + " Price" + dat);
})
var
myJSON = JSON.stringify(lbl);
var
xyz = [lbl];
var
dat1 = [dat];
var
ctx = document.getElementById(
"lineChart1"
);
var
lineChart =
new
Chart(ctx, {
type:
'line'
,
data: {
labels: xyz,
//["January", "February", "March", "April", "May", "June", "July"],
//$.parseJSON(lbl),
datasets: [{
label:
"My First dataset"
,
backgroundColor:
"rgba(38, 185, 154, 0.31)"
,
borderColor:
"rgba(38, 185, 154, 0.7)"
,
pointBorderColor:
"rgba(38, 185, 154, 0.7)"
,
pointBackgroundColor:
"rgba(38, 185, 154, 0.7)"
,
pointHoverBackgroundColor:
"#fff"
,
pointHoverBorderColor:
"rgba(220,220,220,1)"
,
pointBorderWidth: 1,
data: [dat1]
}, {
label:
"My Second dataset"
,
backgroundColor:
"rgba(3, 88, 106, 0.3)"
,
borderColor:
"rgba(3, 88, 106, 0.70)"
,
pointBorderColor:
"rgba(3, 88, 106, 0.70)"
,
pointBackgroundColor:
"rgba(3, 88, 106, 0.70)"
,
pointHoverBackgroundColor:
"#fff"
,
pointHoverBorderColor:
"rgba(151,187,205,1)"
,
pointBorderWidth: 1,
data: [dat1]
}]
},
});
}
});
});
Reply
Answers (
4
)
How to hide and show div using jquery?
How do update text field with selected text from dropdown