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