liuxiaolong
2019-05-09 0d1d88cdb668e75ea8609417ac18ae19947e9525
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
 
       function getCityWenTiBarChart(dom,title,xAxisData,yAxisData){
        
        // 使用
        require(
            [
                'echarts',
                'echarts/chart/bar' // 使用柱状图就加载bar模块,按需加载
            ],
            function (ec) {
                // 基于准备好的dom,初始化echarts图表
                var myChart = ec.init(dom);
                
                var option = {
                        tooltip: {
                            show: true
                        },  title : {
                            text: title,
                            x:'center'
                        },
                        toolbox: {
                            show : false,
                            feature : {
                                mark : {show: true},
                                dataView : {show: true, readOnly: false},
                                magicType : {show: true, type: ['line', 'bar']},
                                restore : {show: true},
                                saveAsImage : {show: true}
                            }
                        }, dataZoom : {
                            show : true,
                            realtime : true,
                            start : 0,
                            end : 100,y: 25, dataBackgroundColor:'rgba(0,0,0,0)',
                        },
                        xAxis : [
                            {
                                type : 'category',
                                data : xAxisData,
                                axisLabel:{
                                    interval:0,
                                    rotate:45,
                                    margin:2,
                                    textStyle:{
                                        color:"#222"
                                    }
                            }
                            }
                        ],
                        yAxis : [
                            {
                                type : 'value'
                            }
                        ],
                        series : [
                            {
                                "name":title,
                                "type":"bar",
                                "data":yAxisData,
                                itemStyle: {
                                    normal: {
                                        color: function (value){ return "#"+("00000"+((Math.random()*16777215+0.5)>>0).toString(16)).slice(-6); }, 
                                        label: {
                                            show: true,
                                            position: 'top',
                                            formatter: function(a){
                                                if(a.value!=0){
                                                    return a.value;
                                                }
                                                else{
                                                    return "";
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        ]
                    };
        
                // 为echarts对象加载数据 
                myChart.setOption(option); 
            }
        );
      }