AAChartView.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. var aaGlobalChart;
  2. function loadTheHighChartView (sender,receivedWidth, receivedHeight) {
  3. var aaOptions = JSON.parse(sender);;
  4. aaOptions.credits = {enabled:false};//去掉表格右下角版权信息
  5. if (aaOptions.plotOptions) {
  6. configurePlotOptions(aaOptions);
  7. }
  8. if (aaOptions.tooltip) {
  9. if (aaOptions.tooltip.formatter) {
  10. aaOptions.tooltip.formatter = eval(aaOptions.tooltip.formatter);
  11. }
  12. }
  13. aaGlobalChart = Highcharts.chart('container', aaOptions);
  14. //全局配置(可通过全局配置设置主题)https://api.hcharts.cn/highcharts#Highcharts.setOptions
  15. };
  16. function configurePlotOptions(aaOptions) {
  17. var aaPlotOptions = aaOptions.plotOptions;
  18. var animation = aaPlotOptions.series.animation;
  19. if (animation) {//懒调用(只有在 AAChartModel 实例对象设置了 animationType 属性值的时候才会调用设置动画类型的函数,否则不调用)
  20. var animationEasingType = animation.easing;
  21. animation.easing = configureTheChartAnimationEasingType(animationEasingType);
  22. }
  23. // 添加鼠标事件
  24. if (aaOptions.touchEventEnabled == true && aaPlotOptions.series) {
  25. configureChartTouchEvent(aaOptions);
  26. }
  27. }
  28. function configureChartTouchEvent(aaOptions) {
  29. var mouseOverFunc = function(){
  30. //console.log(this)
  31. var message = {
  32. name: this.series.name,
  33. y :this.y,
  34. x: this.x,
  35. category:this.category,
  36. offset:{plotX:this.plotX,plotY:this.plotY},
  37. index: this.index,
  38. };
  39. var messageStr = JSON.stringify(message);
  40. // alert("AAChartViewBridge://?"+ messageStr);
  41. window.androidObject.androidMethod(messageStr);
  42. // overrideUrlLoading("AAChartViewBridge://?"+ messageStr);
  43. };
  44. var seriesPoint = {
  45. events:{
  46. mouseOver: mouseOverFunc,
  47. // click: mouseOverFunc,
  48. }
  49. };
  50. aaOptions.plotOptions.series.point = seriesPoint;
  51. }
  52. function overrideUrlLoading(testOverrideUrlStr) {
  53. alert(testOverrideUrlStr);
  54. uiWebViewLoadURL(testOverrideUrlStr);
  55. }
  56. function uiWebViewLoadURL(url) {
  57. var iFrame;
  58. iFrame = document.createElement("iframe");
  59. iFrame.setAttribute("src", url);
  60. iFrame.setAttribute("style", "display:none;");
  61. iFrame.setAttribute("height", "0px");
  62. iFrame.setAttribute("width", "0px");
  63. iFrame.setAttribute("frameborder", "0");
  64. document.body.appendChild(iFrame);
  65. iFrame.parentNode.removeChild(iFrame);
  66. iFrame = null;
  67. }
  68. function onlyRefreshTheChartDataWithSeries (receivedSeries) {
  69. var receivedSeriesElementArr = JSON.parse(receivedSeries);
  70. for (var i = 0; i < receivedSeriesElementArr.length; i++) {
  71. var receivedSeriesData = receivedSeriesElementArr[i].data;
  72. // 获取series
  73. var chartSeries = aaGlobalChart.series[i];
  74. // 执行只刷新数据的函数
  75. chartSeries.setData(receivedSeriesData);
  76. }
  77. }
  78. //pragma mark -- setter method 适应内容https://code.hcharts.cn/highcharts/4YM0a8
  79. function setTheChartViewContentWidth (receivedWidth) {
  80. var container = document.getElementById('container');//获得元素
  81. container.style.width = receivedWidth;//设置宽度
  82. aaGlobalChart.reflow();
  83. }
  84. function setTheChartViewContentHeight (receivedHeight) {
  85. var container = document.getElementById('container');//获得元素
  86. container.style.height = receivedHeight;//设置高度
  87. aaGlobalChart.reflow();
  88. }
  89. function setChartSeriesHidden(hidden) {
  90. for (var i = 0; i < aaGlobalChart.series.length; i++) {
  91. var series = aaGlobalChart.series[i];
  92. if (hidden == true) {
  93. series.hide();
  94. } else {
  95. series.show();
  96. }
  97. }
  98. }
  99. function showTheSeriesElementContentWithIndex (elementIndex) {
  100. var series = aaGlobalChart.series[elementIndex];
  101. series.show();
  102. }
  103. function hideTheSeriesElementContentWithIndex(elementIndex) {
  104. var series = aaGlobalChart.series[elementIndex];
  105. series.hide();
  106. }