Teach you to make a simple highchart.js chart

Source: Internet
Author: User

1.js notation:

$ (function () {
Draw ();//Render when page is opened

})
function Draw () {

var arrloginname = [], arrliveness = [];//highchart can read the array, so your defined parameters should be an array
var form = $ ("form"). Serialize ();
$.ajax ({
URL: "/ffmanager/statistics/getcustomerincome/",
Type: "POST",
async:false,//Synchronous Refresh Ajax, this is very important, otherwise loading data
Cache:false,
DataType: "JSON",
Data:form,
Success:function (data, Textstatus, XMLHttpRequest) {

var result = data,//Data obtained from the C # back end
rows = result.rows;

if (!! rows) {
for (var i = 0, length = rows.length; i < length; i++) {
Arrloginname.push (Rows[i]. LoginName);
Arrliveness.push (Rows[i]. Price);
}
}
},
Error:function (XMLHttpRequest, Textstatus, Errorthrown) {

}
});

$ (' #canvasParent '). Highcharts ({
Chart: {
Type: ' column '
},
Title: {
Text: ' Customer points out revenue ',
Style: {
Color: ' #6495ED ',
FontWeight: ' Bold ',
FontSize: ' 20px '
}
},
Xaxis: {
CategoriesArrloginname,//The data of the x-axis transmitted over the background
Title: {
Text: ' Client '
}
},
YAxis: {
min:0,
Title: {
Text: ' Amount (yuan) ',
Align: ' high '
},
Labels: {
Overflow: ' Justify '
}
},
ToolTip: {
Valuesuffix:null
},
Plotoptions: {
Bar: {
DataLabels: {
Enabled:true
}
}
},
Legend: {
Layout: ' Vertical ',
Align: ' right ',
VerticalAlign: ' Top ',
X:-40,
Y:80,
Floating:true,
Borderwidth:1,
BackgroundColor: ((highcharts.theme && Highcharts.theme.legendBackgroundColor) | | ' #FFFFFF '),
Shadow:true
},
Credits: {
Enabled:false
},
Series: [{
Name: ' Customer answers revenue ',
DataarrlivenessThe back end of the y-axis data is important for these two data, others can be pasted copy
}]
});
}

Back-end data (C #):

Public Jsonresult getcustomerincome (formcollection form)
{
String strstarttime = form["StartTime"]?? "";
String strendtime = form["EndTime"]?? "";
int count = Convert.ToInt32 (form["SelectCount"]?? "0");
Time interval
String strinterval = form["Interval"]?? "";
Time designation
String strassign = form["Assign"]?? "";

ilist<model.runui.customerincome> lectureincomelist = Bllstatistics.getcustomerincome (StrStartTime, Strendtime, Strinterval, Strassign, Currentuser.employeeid);

if (lectureincomelist = = null) return Json (new object[] {}, jsonrequestbehavior.allowget);
var data = lectureincomelist.select (m = = new
{
M.customerid,
M.loginname,
M.nickname,
M.truename,
M.price,//Income amount
M.datetime,//Time
}). Take (count);
Return Json (New {rows = data}, Jsonrequestbehavior.allowget);
}

* The back end has price, and loginname two fields, the two fields as Y and X axis, in JS into an array, each corresponding display *

Teach you to make a simple highchart.js chart

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.