js分享2
/* ** Author: hzhang.Ashe ** Date : 2015.07.23 ** Descri: 多基金-资产配置(图形) */ (function (window) { //构造函数 var oClass = function () { }; var colorOptions = [{ name: "stock", text: "股票", color: GlobalColors[0] }, { name: "bond", text: "债券", color: GlobalColors[1] }, { name: "fund", text: "基金", color: GlobalColors[2] }, { name: "cash", text: "现金", color: GlobalColors[3] }, { name: "other", text: "其他", color: GlobalColors[4] }]; var chartItemColorsVal = [{ name: "stock", color: GlobalColors[0] }, { name: "bond", color: GlobalColors[1] }, { name: "fund", color: GlobalColors[2] }, { name: "cash", color: GlobalColors[3] }, { name: "other", color: GlobalColors[4] }]; oClass.defaultOption = { SettingProperty: { title: '资产配置', hideHead: null, reportPeriod: null, showTimeRangeLabel: 1, chartType: 'column', chartItemColors: { opts: colorOptions, dVal: chartItemColorsVal } } } //初始化 oClass.prototype.Init = function () { this.content.append("<div class='chart'></div>"); this.GetData(); }; //数据获取 oClass.prototype.GetData = function () { var _self = this; var setting = this.options.setting; var parameters = [setting.windCodes, setting.reportPeriod]; var dataParameters = { MethodAlias: 'MFRB_GetMultiFundAssetAllocationChartData', Parameter: parameters }; AjaxRequest(ajaxSecureUnlockHandler, dataParameters, function (result) { _self.BindData(result); }); this.content.block(); }; //数据绑定 oClass.prototype.BindData = function (result) { var _self = this; //初始化报表 function _ChartInit(categories, series) { //绘制Item的颜色 $.each(series, function (index, item) { if (_self.options.setting.chartItemColors && _self.options.setting.chartItemColors.length > 0) { item.color = _self.options.setting.chartItemColors[index].color; } }); //转换chart数据 convertChartData(series); //绘制highcharts _self.CreateChart(_self.content.find(".chart"), { xAxis: { categories: categories }, yAxis: { labels: { format: "{value}%" } , title: { text: '占基金总资产比' } }, plotOptions: { column: { stacking: 'percent' }, area: { stacking: 'percent' } }, series: series }); }; //Ajax回调处理 if (result.State == 0 && result.Data.Categories && result.Data.Series) { //隐藏Loading _self.content.unblock(); _ChartInit(result.Data.Categories, result.Data.Series); } else { this.content.block(WFCFrame.GetNoDataBlockOption('无数据')); } }; //刷新 oClass.prototype.Refresh = function () { this.GetData(); }; //自适应 oClass.prototype.Resize = function () { this.content.find('.chart').each(function () { var chart = $(this).highcharts(); if (chart) { chart.setSize($(this).width(), $(this).height()); } }); }; //注册widget window.WFCFrame.RegisterWidget('MultiFundAssetAllocationChart', oClass); })(window);