function t1(stock,code,name,lang,_title,close){ var opt_url; if(stock === "hk"){ opt_url = "//data.gtimg.cn/flashdata/hk/minute/hk"+ code + ".js"; $.ajax({ type: "get", url: opt_url, datatype:"script", success:function(){ var data_t1 = format_t1(min_data); var data0_t1 = splitdata_t1(data_t1,close); if(stock == "hk"){ var timearr = gettimearr_hk(); var option_t1 = opt_t1_hk(name,data0_t1,lang,_title,timearr); }else{ var timearr = gettimearr(); var option_t1 = opt_t1(name,data0_t1,lang,_title,timearr); } var mychart = echarts.init(document.getelementbyid("main2")); mychart.setoption(option_t1) } }); }else{ $.ajax({ type:"get", url:"//web.ifzq.gtimg.cn/appstock/app/minute/query?_var=min_data_"+ stock +code+"&code=" + stock +code, datatype:"script", cache:"false", success:function(){ var res = evil('min_data_' + stock +code) var stkcode = stock + code; if(res.code == 0){ var obj_arr=res['data'][stkcode]['data']['data'], obj_date=res['data'][stkcode]['data']['date']; obj_date=obj_date.slice(2, obj_date.length); min_data_f='date:'+obj_date+"\n" for(i in obj_arr){ min_data_f+=obj_arr[i]+"\n" } var data_t1 = format_t1(min_data_f); var data0_t1 = splitdata_t1(data_t1,close); if(stock == "hk"){ var timearr = gettimearr_hk(); var option_t1 = opt_t1_hk(name,data0_t1,lang,_title,timearr); }else{ var timearr = gettimearr(); var option_t1 = opt_t1(name,data0_t1,lang,_title,timearr); } var mychart = echarts.init(document.getelementbyid("main")); mychart.setoption(option_t1) } }, error:function(){ //icom.alert('请求失败') console.log('请求失败') //请求出错处理 } }); }; }; function timestamptodate(stamp,lang){ var idate = new date(number(stamp)); var iyear = idate.getfullyear(); var imonth = idate.getmonth() + 1; imonth = imonth < 10 ? "0" + imonth : imonth; var itoday = idate.getdate(); itoday = itoday < 10 ? "0" + itoday : itoday; if(lang == "cn"){ var iday = numtocn(idate.getday()); }else{ var iday = numtoen(idate.getday()); } var ihour = idate.gethours(); var imin = idate.getminutes(); imin = imin < 10 ? "0" + imin : imin; return iyear + "/" + imonth + "/" + itoday + " " + iday + " " + ihour + ":" + imin } // 提示框中文格式回调封装 function tooltip_t1(stock,lang,param,data,name){ var html = "" if(param[0].componentsubtype == "line"){ if(lang == "cn"){ var til_a = "价格"; var til_b = "涨跌幅"; var til_c = "成交量"; }else{ var til_a = "price" var til_b = "change" var til_c = "volume" }; var _volume = data.volume[param[0].dataindex]; if(_volume >= 10000){ _volume = showm(lang,_volume,stock) } html += '
' + name + '
' + '
' + timestamptodate(param[0].axisvalue,lang) + '
' + '
' + '' + til_a + ':' + todecimal(param[0].value) + '
' + '' + til_b + ':' + todecimal(param[1].value) + "%" + '
' + '' + til_c + ':' + _volume + '
' } return html; } function opt_t1(name,data,lang,_title,xarr){ // y轴左坐标 价格最大值、最小值及刻度 var valuemax = math.max.apply(null,data.values); var valuemin = math.min.apply(null,data.values); var valueint = (valuemax - valuemin) / 5; // y轴右坐标 涨跌幅最大值、最小值及刻度 var changemax = math.max.apply(null,data.changep); var changemin = math.min.apply(null,data.changep); var changeint = (changemax - changemin) / 5; var dis_lens = xarr.length - data.values.length for(var i = 0; i < dis_lens;i++){ data.categorydata.push("-"); data.values.push("-"); data.volume.push("-"); data.changep.push("-"); }; var upcolor = '#ec0000'; var upbordercolor = '#8a0000'; var downcolor = '#00da3c'; var downbordercolor = '#008f28'; // 提示框参数配置 var settooltip = { trigger: 'axis', axispointer: { type: 'cross' }, formatter:function(param){ return tooltip_t1("hushen",lang,param,data,name) } }; return { title: { text: _title, left: 0 }, tooltip: settooltip, grid: { left: '10%', right: '15%', bottom: '10%' }, xaxis: { type: 'category', splitnumber: 8, splitline:{ show:false }, data:xarr, min:"datamin", max:"datamax", scale: true, boundarygap : false, axispointer: { label:{ formatter:function(params){ return timestamptodate(number(params.value),lang) } } }, axisline: {onzero: false}, axislabel:{ showminlabel: true, showmaxlabel: true, interval: 29, formatter:function(value,index){ var data = new date(number(value)); var hours = data.gethours(); if(hours == 9 || hours == 11){ hours = hours < 10 ? '0' + hours : hours; var minutes = data.getminutes(); if(minutes == 30){ var time = hours + ':' + minutes; } } if(hours > 12){ var minutes = data.getminutes(); if(minutes == 0){ var time = hours + ':0' + minutes; } } return time } } }, yaxis: [{ type: 'value', min: 'datamin', max: 'datamax', splitnumber:5, interval:valueint, scale: true, splitarea: { show: true }, axispointer: { label:{ formatter:function(params){ return todecimal(params.value) } } }, axislabel:{ formatter:function(value,index){ return todecimal(value) } } }, { type: 'value', min: 'datamin', max: 'datamax', splitnumber: 5, interval:changeint, scale: true, splitarea: { show: true }, axispointer: { label:{ formatter:function(params){ return todecimal(params.value) + "%" } } }, axislabel:{ formatter:function(value,index){ value = todecimal(value) > 0 ? "+" + todecimal(value) : todecimal(value); return value + "%" } } }], series: [{ name:"价格", type: 'line', yaxisindex: 0, data: data.values, },{ name:"涨跌幅", type: 'line', yaxisindex: 1, data: data.changep, linestyle: { opacity: 0 }, itemstyle:{ opacity: 0 } }] }; } function opt_t1_hk(name,data,lang,_title,xarr){ // y轴左坐标 价格最大值、最小值及刻度 var valuemax = math.max.apply(null,data.values); var valuemin = math.min.apply(null,data.values); var valueint = (valuemax - valuemin) / 5; // y轴右坐标 涨跌幅最大值、最小值及刻度 var changemax = math.max.apply(null,data.changep); var changemin = math.min.apply(null,data.changep); var changeint = (changemax - changemin) / 5; var dis_lens = xarr.length - data.values.length for(var i = 0; i < dis_lens;i++){ data.categorydata.push("-"); data.values.push("-"); data.volume.push("-"); data.changep.push("-"); }; var upcolor = '#ec0000'; var upbordercolor = '#8a0000'; var downcolor = '#00da3c'; var downbordercolor = '#008f28'; // 提示框参数配置 var settooltip = { trigger: 'axis', axispointer: { type: 'cross' }, formatter:function(param){ return tooltip_t1("hk",lang,param,data,name) } }; return { title: { text: _title, left: 20, top:5 }, tooltip: settooltip, grid: { left: '10%', right: '15%', bottom: '10%' }, xaxis: { type: 'category', splitnumber: 11, splitline:{ show:false }, data:xarr, min:"datamin", max:"datamax", scale: true, boundarygap : false, axispointer: { label:{ formatter:function(params){ return timestamptodate(number(params.value),lang) } } }, axisline: {onzero: false}, axislabel:{ showminlabel: true, showmaxlabel: true, interval: 29, formatter:function(value,index){ var data = new date(number(value)); var hours = data.gethours(); if(hours == 9){ hours = hours < 10 ? '0' + hours : hours; var minutes = data.getminutes(); if(minutes == 30){ var time = hours + ':' + minutes; } } if(hours >= 12){ var minutes = data.getminutes(); if(minutes == 0){ var time = hours + ':0' + minutes; } } return time } } }, yaxis: [{ type: 'value', min: 'datamin', max: 'datamax', splitnumber:5, interval:valueint, scale: true, splitarea: { show: true }, axispointer: { label:{ formatter:function(params){ return todecimal(params.value) } } }, axislabel:{ formatter:function(value,index){ return todecimal(value) } } }, { type: 'value', min: 'datamin', max: 'datamax', splitnumber: 5, interval:changeint, scale: true, splitarea: { show: true }, axispointer: { label:{ formatter:function(params){ return todecimal(params.value) + "%" } } }, axislabel:{ formatter:function(value,index){ value = todecimal(value) > 0 ? "+" + todecimal(value) : todecimal(value); return value + "%" } } }], series: [{ name:"价格", type: 'line', yaxisindex: 0, data: data.values, },{ name:"涨跌幅", type: 'line', yaxisindex: 1, data: data.changep, linestyle: { opacity: 0 }, itemstyle:{ opacity: 0 } }] }; } function format_t1(data){ var res = json.stringify(data).split("\\n"); //提取有效数据 if(res[0] == '"'){ res = res.splice(2) }else{ res = res.splice(1) }; if(res[res.length - 1] =='"'){ res = res.splice(0,res.length - 1) } var _data = []; $.each(res,function(i,n){ var arr = n.split(" "); var time = arr[0].slice(0,2) + ":" + arr[0].slice(2,4); arr.splice(0,1,time); $.each(arr,function(index,item){ if(index > 0){ var _item = number(item); arr.splice(index,1,_item) } }); _data.push(arr); }); return _data } function splitdata_t1(rawdata,close) { var categorydata = []; var values = []; var volume = []; var changep = []; for (var i = 0; i < rawdata.length; i++) { categorydata.push(rawdata[i][0]); values.push(rawdata[i][1]); if(i > 0){ volume.push(rawdata[i][2] - rawdata[i-1][2]) }else{ volume.push(rawdata[i][2]) }; changep.push(todecimal((rawdata[i][1] - close) / close * 100)) }; return { categorydata: categorydata, values: values, volume:volume, changep:changep }; }; // 建立数组[9:30,...,15:00]作x轴刻度显示 function gettimearr(){ var timearr = []; var now_data = new date(); var now_year = now_data.getfullyear(), now_month = now_data.getmonth() + 1, now_day = now_data.getdate(); var str_time = now_year + '/' + now_month + '/' + now_day +' 09:30'; var tt = new date(str_time).gettime(); for(i = 0;i <= 330; i++){ var value = new date(number(tt)); var hours = value.gethours(); switch(hours){ case 11: var minutes = value.getminutes(); if(minutes <= 30){ timearr.push(tt); }; break; case 12: break; default: timearr.push(tt); }; tt = tt + 60000 }; return timearr } function gettimearr_hk(){ var timearr = []; var now_data = new date(); var now_year = now_data.getfullyear(), now_month = now_data.getmonth() + 1, now_day = now_data.getdate(); var str_time = now_year + '/' + now_month + '/' + now_day +' 09:30'; var tt = new date(str_time).gettime(); for(i = 0;i <= 390; i++){ var value = new date(number(tt)); var hours = value.gethours(); switch(hours){ case 12: var minutes = value.getminutes(); if(minutes == 0){ timearr.push(tt); }; break; default: timearr.push(tt); }; tt = tt + 60000 }; return timearr }