/*
 * 特别声明：本技术材料受《中华人民共和国著作权法》、《计算机软件保护条例》等法律、法规、行政
 * 规章以及有关国际条约的保护，赞同科技享有知识产权、保留一切权利并视其为技术秘密。未经本公司书
 * 面许可，任何人不得擅自（包括但不限于：以非法的方式复制、传播、展示、镜像、上载、下载）使用，
 * 不得向第三方泄露、透露、披露。否则，本公司将依法追究侵权者的法律责任。特此声明！
 *
 * Special Declaration: These technical material reserved as the technical secrets by AGREE
 * TECHNOLOGY have been protected by the "Copyright Law" "ordinances on Protection of Computer
 * Software" and other relevant administrative regulations and international treaties. Without
 * the written permission of the Company, no person may use (including but not limited to the
 * illegal copy, distribute, display, image, upload, and download) and disclose the above
 * technical documents to any third party. Otherwise, any infringer shall afford the legal
 * liability to the company.
 */
/**
 * Created by huangdeyun on 2015/9/15 10:33.
 */
define(['echarts', 'echarts/chart/bar'], function (ECharts, Bar) {
    return {
        init: function (myCharts_, mainNode, title, subTitle, xAxis, names, values) {
            if (xAxis.length === 0 || names.length === 0 || values.length === 0) {
                return myCharts_;
            }
            var myCharts = myCharts_;
            if (!myCharts) {
                myCharts = ECharts.init(mainNode);
            }
            myCharts.clear();
            /*//测试数据
             var title = "某地区蒸发量和降水量";
             var subTitle = '';
             var xAxis = ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'];
             var names = ['蒸发量', '降水量'];
             var values = [
             [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3],
             [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3],
             ];*/
            var datas = [];
            for (var i = 0; i < names.length; i++) {
                datas.push({
                    name: names[i],
                    type: 'bar',
                    data: values[i]
                });
            }
            var option = {
                title: {
                    text: title,
                    subtext: subTitle
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data: names,
                    selectedMode: false,//图例开关，默认开启
                },
                toolbox: {
                    show: false
                },
                calculable: false,
                xAxis: [
                    {
                        type: 'category',
                        data: xAxis,
                        axisLabel: {
                            textStyle: {
                                color: "#ff0000"
                            }
                        }
                    }
                ],

                yAxis: [
                    {
                        type: 'value',
                        axisLabel: {
                            textStyle: {
                                color: "#ff0000"
                            }
                        }
                    }
                ],
                series: datas
            };
            myCharts.setOption(option);
            return myCharts;
        }
    };
});