AAChartView.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. var aaGlobalChart;
  2. function loadTheHighChartView (sender,receivedWidth, receivedHeight) {
  3. var aaOptions = JSON.parse(sender, function (key, value) {
  4. if ( typeof(value) == 'string'
  5. && value.indexOf('function') != -1) {
  6. return eval(value)
  7. }
  8. return value;
  9. });
  10. if (aaOptions.xAxisArray) {
  11. aaOptions.xAxis = aaOptions.xAxisArray
  12. }
  13. if (aaOptions.yAxisArray) {
  14. aaOptions.yAxis = aaOptions.yAxisArray
  15. }
  16. aaOptions.credits = {enabled:false};
  17. if (aaOptions.defaultOptions) {
  18. Highcharts.setOptions({
  19. lang: aaOptions.defaultOptions
  20. });
  21. }
  22. if (aaOptions.plotOptions) {
  23. configurePlotOptions(aaOptions);
  24. }
  25. aaGlobalChart = Highcharts.chart('container', aaOptions);
  26. //全局配置(可通过全局配置设置主题)https://api.hcharts.cn/highcharts#Highcharts.setOptions
  27. };
  28. function configurePlotOptions(aaOptions) {
  29. var aaPlotOptions = aaOptions.plotOptions;
  30. var animation = aaPlotOptions.series.animation;
  31. if (animation) {//懒调用(只有在 AAChartModel 实例对象设置了 animationType 属性值的时候才会调用设置动画类型的函数,否则不调用)
  32. var animationEasingType = animation.easing;
  33. animation.easing = configureTheChartAnimationEasingType(animationEasingType);
  34. }
  35. // 添加鼠标事件
  36. if (aaOptions.touchEventEnabled == true && aaPlotOptions.series) {
  37. configureChartTouchEvent(aaPlotOptions);
  38. }
  39. }
  40. function configureChartTouchEvent(aaPlotOptions) {
  41. var mouseOverFunc = function(){
  42. var message = {
  43. name: this.series.name,
  44. y :this.y,
  45. x: this.x,
  46. category: this.category,
  47. offset: {plotX:this.plotX,plotY:this.plotY},
  48. index: this.index,
  49. };
  50. var messageStr = JSON.stringify(message);
  51. window.androidObject.androidMethod(messageStr);
  52. };
  53. if (aaPlotOptions.series.point) {// set property directly for series point
  54. aaPlotOptions.series.point.events.mouseOver = mouseOverFunc;
  55. } else {// create a new series point object instance
  56. var seriesPoint = {
  57. events:{
  58. mouseOver: mouseOverFunc,
  59. }
  60. };
  61. aaPlotOptions.series.point = seriesPoint;
  62. }
  63. }
  64. function onlyRefreshTheChartDataWithSeries(receivedSeries, animation) {
  65. var receivedSeriesArr = JSON.parse(receivedSeries);
  66. var seriesArrLength = receivedSeriesArr.length;
  67. for (var i = 0; i < seriesArrLength; i++) {
  68. var receivedSeriesElementData = receivedSeriesArr[i].data;
  69. // 获取series
  70. var seriesElement = aaGlobalChart.series[i];
  71. // 执行只刷新数据的函数
  72. seriesElement.setData(receivedSeriesElementData, false);
  73. }
  74. var animationBool = (animation == "true") ? true:false;
  75. aaGlobalChart.redraw(animationBool);
  76. }
  77. function updateChart(optionsStr, redraw) {
  78. var options = JSON.parse(optionsStr);
  79. aaGlobalChart.update(options,redraw);
  80. }
  81. function addPointToChartSeries(elementIndex, optionsStr, redraw, shift, animation) {
  82. var options = JSON.parse(optionsStr);
  83. var redrawBool = (redraw == "true") ? true:false;
  84. var shiftBool = (shift == "true") ? true:false;
  85. var animationBool = (animation == "true") ? true:false;
  86. var seriesElement = aaGlobalChart.series[elementIndex];
  87. seriesElement.addPoint(options, redrawBool, shiftBool, animationBool);
  88. }
  89. //pragma mark -- setter method
  90. function setTheChartViewContentWidth(receivedWidth) {
  91. var container = document.getElementById('container'); //获得元素
  92. container.style.width = receivedWidth; //设置宽度
  93. aaGlobalChart.reflow();
  94. }
  95. function setTheChartViewContentHeight(receivedHeight) {
  96. var container = document.getElementById('container'); //获得元素
  97. container.style.height = receivedHeight; //设置高度
  98. aaGlobalChart.reflow();
  99. }
  100. function setChartSeriesHidden(hidden) {
  101. for (var i = 0; i < aaGlobalChart.series.length; i++) {
  102. var seriesElement = aaGlobalChart.series[i];
  103. if (hidden == true) {
  104. seriesElement.hide();
  105. } else {
  106. seriesElement.show();
  107. }
  108. }
  109. }
  110. function showTheSeriesElementContentWithIndex(elementIndex) {
  111. var seriesElement = aaGlobalChart.series[elementIndex];
  112. seriesElement.show();
  113. }
  114. function hideTheSeriesElementContentWithIndex(elementIndex) {
  115. var seriesElement = aaGlobalChart.series[elementIndex];
  116. seriesElement.hide();
  117. }
  118. function addElementToChartSeriesWithElement(elementStr) {
  119. var seriesElement = JSON.parse(elementStr);
  120. aaGlobalChart.addSeries(seriesElement);
  121. }
  122. function removeElementFromChartSeriesWithElementIndex(elementIndex) {
  123. var seriesElement = aaGlobalChart.series[elementIndex];
  124. if (seriesElement) {
  125. seriesElement.remove(true);
  126. }
  127. }
  128. function evaluateTheJavaScriptStringFunction(jsStringFunction) {
  129. eval(jsStringFunction);
  130. }