MajorQuoteTrendHighCharts.cshtml 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. 
  2. @{
  3. Layout = null;
  4. }
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta name="viewport" content="width=device-width" />
  9. <title>MajorQuoteTrendHighCharts</title>
  10. <script src="~/Content/js/jquery.min.js"></script>
  11. @*<script src="~/Content/plugins/highcharts/highcharts.js"></script>*@
  12. <script src="~/Content/plugins/highcharts/highcharts5.0.14.js"></script>
  13. <script type="text/javascript" src="~/Content/plugins/highcharts/modules/exporting.js"></script>
  14. </head>
  15. <body>
  16. <div id="container" style="Z-INDEX: 103; LEFT: 5px; WIDTH: 1000px; POSITION: absolute; TOP: 120px; HEIGHT: 400px"></div>
  17. <script>
  18. var chart;
  19. function LoadChart() {
  20. if (true) {
  21. chart = new Highcharts.Chart({
  22. chart: {
  23. renderTo: 'container',
  24. defaultSeriesType: 'spline',
  25. events: {
  26. load: ChartQry
  27. }
  28. },
  29. title: {
  30. text: ''
  31. },
  32. xAxis: {
  33. categories: [],
  34. tickWidth: 3,
  35. tickmarkPlacement: 'on',
  36. labels: {
  37. rotation: 0,
  38. align: 'center',
  39. formatter: function () {
  40. // x轴的日期进行格式化
  41. var days = this.value.split('/');
  42. if (days.length == 3)
  43. return days[1] + '/' + days[2];
  44. else
  45. return this.value;
  46. }
  47. }
  48. },
  49. yAxis: {
  50. title: {
  51. text: ''
  52. }
  53. },
  54. tooltip: {
  55. enabled: true,
  56. formatter: function () {
  57. return '<b>' + this.series.name + '</b><br/>' +
  58. this.x + ': ' + Highcharts.numberFormat(this.y, 2) + '元';
  59. }
  60. },
  61. exporting: {
  62. buttons: {
  63. printButton: {
  64. enabled: false
  65. },
  66. exportButton: {
  67. enabled: false,
  68. menuItems: [{
  69. text: 'PNG格式',
  70. onclick: function () {
  71. this.exportChart({
  72. type: 'image/png',
  73. width: 1200
  74. });
  75. }
  76. }, {
  77. text: 'JPG格式',
  78. onclick: function () {
  79. this.exportChart({
  80. type: 'image/jpeg',
  81. width: 1200
  82. });
  83. }
  84. },
  85. null,
  86. null]
  87. }
  88. },
  89. //url: 'HighchartsExport.aspx',
  90. url: 'http://export.highcharts.com.cn',
  91. filename: 'MyChart',
  92. width: 1200
  93. },
  94. plotOptions: {
  95. spline: {
  96. dataLabels: {
  97. enabled: true, // 是否在线上各点标注y轴数值
  98. formatter: function () {
  99. return Highcharts.numberFormat(this.y, 2);
  100. }
  101. },
  102. enableMouseTracking: true
  103. }
  104. },
  105. credits: {
  106. enabled: false
  107. },
  108. series: [{
  109. name: '最高价',
  110. color: '#C85B6F',
  111. data: []
  112. }, {
  113. name: '最低价',
  114. color: '#15AE67',
  115. data: []
  116. }, {
  117. name: '平均价',
  118. //color: '#59C3E2',
  119. color: 'gray',
  120. dashStyle: 'longdash',
  121. data: []
  122. }]
  123. });
  124. }
  125. }
  126. function ChartQry() {
  127. $.ajax({
  128. url: '@Url.Action("ShowChartMajorQuoteTrendHighCharts", "DataCharts")', // 查询接口
  129. type: 'post',
  130. dataType: 'json', // 查询接口返回的数据类型
  131. timeout: 10000000, // 单位=毫秒。为了测试写成1000秒,正式环境下可改为20秒
  132. data: {
  133. ChartType: 'LINE'
  134. },
  135. success: function (srv_resp, textStatus) {
  136. // 查询接口无数据返回
  137. var count = eval(srv_resp.__totalcount);
  138. if (count == "" || count == null || count == "undefined" || count <= 0) {
  139. return;
  140. }
  141. if (true) {
  142. chart.xAxis[0].setCategories(srv_resp.__categories);
  143. if (srv_resp.__series.length == 3) {
  144. // 设置x轴label间隔,否则可能因为数据量而过密
  145. var step = Math.ceil(count / 10.0);
  146. if (step < 1) { step = 1; }
  147. //chart.xAxis[0].options.labels.step = step;
  148. chart.xAxis[0].options.tickInterval = step;
  149. // 设置各series的数据
  150. chart.series[0].setData(srv_resp.__series[0], false);
  151. chart.series[1].setData(srv_resp.__series[1], false);
  152. chart.series[2].setData(srv_resp.__series[2], false);
  153. chart.redraw();
  154. }
  155. }
  156. },
  157. // 捕获出错信息(服务器应答超时、返回数据不是json格式等,用于调试)
  158. error: function (xmlHttpRequest, textStatus) {
  159. layer.alert(textStatus, { icon: 2, title: '提示信息' });
  160. },
  161. cache: false
  162. });
  163. };
  164. $(function () {
  165. LoadChart();
  166. //加载日历控件
  167. //$("#hid_ChartType").val("LINE");
  168. });
  169. </script>
  170. </body>
  171. </html>