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.