C # Use HighCharts,

Source: Internet
Author: User

C # Use HighCharts,

I recently received a requirement for a graphical report. I found several plug-ins on the network and finally decided to use highcharts.

Required file

1. bll file, added to project reference http://files.cnblogs.com/files/lovejunjuan/HighChartsMvc.Model.rar

2. js file, add reference http://files.cnblogs.com/files/lovejunjuan/highcharts.js in the project

 

Reference bll files

@ Using HighChartsMvc. Model. Chart;
@ Using HighChartsMvc. Model. Chart. SeriesStlye;

 

Reference js files

<Script src = "@ Url. Content ("~ /Content/Highcharts-4.2.6/js/highcharts. js ")" type = "text/javascript"> </script>

 

Ajax obtains data from the background and binds it to the control.

$. Ajax ({type: 'get', url: durl, // request data address success: function (data) {var json = eval ("(" + data + ") "); alert (json); var s = 1; for (var key in json. list) {json. list [key]. y = json. list [key]. age; // assign xtext = json to the Y axis. list [key]. name; // assign json to the x-axis TEXT. list [key]. color = color [key];} chart. series [0]. setData (json. list); // fill in the data above highcharts}, error: function (e) {}}); var chart = new Highcharts. chart ({chart: {renderTo: 'Container', type: 'column' // display type column, which can be changed to another type, pie Chart, and so on. data binding methods are the same, very convenient}, title: {text: 'yield distribution fig' // chart title}, xAxis: {categories: xtext}, yAxis: {title: {text: 'generation' // y axis name },}, series: [{name: ""}]});

Json Data Format

Public string DataTableToJson (DataTable dt) {StringBuilder jsonBuilder = new StringBuilder (); jsonBuilder. append ("{\" "); jsonBuilder. append ("list"); jsonBuilder. append ("\": ["); for (int I = 0; I <dt. rows. count; I ++) {jsonBuilder. append ("{"); for (int j = 0; j <dt. columns. count; j ++) {jsonBuilder. append ("\" "); jsonBuilder. append (dt. columns [j]. columnName); jsonBuilder. append ("\": "); // jsonBuilder. append ("\": \ ""); // determines whether the value is a pure number. if (IsNumber (dt. rows [I] [j]. toString () {jsonBuilder. append (dt. rows [I] [j]. toString ();} else {jsonBuilder. append ("\" "); jsonBuilder. append (dt. rows [I] [j]. toString (); jsonBuilder. append ("\" ");} jsonBuilder. append (","); // jsonBuilder. append ("\", ");} jsonBuilder. remove (jsonBuilder. length-1, 1); jsonBuilder. append ("},");} jsonBuilder. remove (jsonBuilder. length-1, 1); jsonBuilder. append ("]"); jsonBuilder. append ("}"); return jsonBuilder. toString ();}

Other parameters have not been studied too much. Please refer to the official website.

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.