function dk(stock,code,name,lang,_title,_serious){ var opt_url; if(stock === "hk"){ opt_url = "http://data.gtimg.cn/flashdata/hk/latest/daily/"; }else{ opt_url = "http://data.gtimg.cn/flashdata/hushen/latest/daily/"; }; // 日k $.ajax({ type: "get", url: opt_url + stock + code + ".js?maxage=43201&visitdsttime=1", datatype:"script", success:function(){ var d_data = format(latest_daily_data,lang); var d_data0 = splitdata(d_data); var d_option = opt_dk(name,d_data0,lang,_title,_serious); // 2. 创建echarts实例 var mychart = echarts.init(document.getelementbyid('main')); // 3. 作用 mychart.setoption(d_option); } }); } // 提示框中文格式回调封装 function tooltip_dk(lang,param,name){ var html = ""; if(lang == "cn"){ var til_op = '开盘值:' var til_cl = '收盘值:' var til_hi = '最高值:' var til_low = '最低值:' var value_hi = param[0].value[3] var value_low = param[0].value[4] }else{ var til_op = 'open:' var til_cl = 'close:' var til_hi = 'highest:' var til_low = 'lowest:' var value_hi = param[0].value[4] var value_low = param[0].value[3] } if(param[0].componentsubtype == "candlestick"){ html += '
' + name + '
' + '
' + param[0].name + '
' + '
' + '' + param[0].seriesname + ":" + '
' + '' + til_op + todecimal(param[0].value[1]) + '
' + '' + til_cl + todecimal(param[0].value[2]) + '
' + '' + til_hi + todecimal(value_hi) + '
' + '' + til_low + todecimal(value_low) + '
' } return html; } // echarts配置 function opt_dk(name,data,lang,_title,_serious){ // 提示框参数配置 var settooltip = { trigger: 'axis', axispointer: { type: 'cross' }, formatter:function(param){ return tooltip_dk(lang,param,name) } }; // if(lang == "cn"){ // settooltip.formatter = function(param){ // } // }; // 1. 柱状图样式定义 var upcolor = '#ec0000'; var upbordercolor = '#8a0000'; var downcolor = '#00da3c'; var downbordercolor = '#008f28'; return { title: { text: _title, left: 0 }, tooltip: settooltip, // legend: { // data: _legend // }, grid: { left: '10%', right: '10%', bottom: '15%' }, xaxis: { type: 'category', data: data.categorydata, scale: true, boundarygap : false, axisline: {onzero: false}, splitline: {show: false}, splitnumber: 20, min: 'datamin', max: 'datamax' }, yaxis: { scale: true, splitarea: { show: true }, axispointer: { label:{ formatter:function(params){ return todecimal(params.value) } } }, axislabel:{ formatter:function(value,index){ return todecimal(value) } } }, datazoom: [ { type: 'inside', start: 50, end: 100 }, { show: true, type: 'slider', y: '90%', start: 50, end: 100 } ], series: [ { name: _serious, type: 'candlestick', data: data.values, itemstyle: { normal: { color: upcolor, color0: downcolor, bordercolor: upbordercolor, bordercolor0: downbordercolor } }, markpoint: { label: { normal: { formatter: function (param) { return param != null ? math.round(param.value) : ''; } } }, data: [ { name: 'xx标点', coord: ['2019/5/31', 2300], value: 2300, itemstyle: { normal: {color: 'rgb(41,60,85)'} } }, { name: 'highest value', type: 'max', valuedim: 'highest' }, { name: 'lowest value', type: 'min', valuedim: 'lowest' }, { name: 'average value on close', type: 'average', valuedim: 'close' } ], tooltip: { formatter: function (param) { return param.name + '
' + (param.data.coord || ''); } } }, markline: { symbol: ['none', 'none'], data: [ [ { name: 'from lowest to highest', type: 'min', valuedim: 'lowest', symbol: 'circle', symbolsize: 10, label: { normal: {show: false}, emphasis: {show: false} } }, { type: 'max', valuedim: 'highest', symbol: 'circle', symbolsize: 10, label: { normal: {show: false}, emphasis: {show: false} } } ], { name: 'min line on close', type: 'min', valuedim: 'close', label:{ formatter:function(param){ return todecimal(param.value) } } }, { name: 'max line on close', type: 'max', valuedim: 'close', label:{ formatter:function(param){ return todecimal(param.value) } } } ] } }, // { // name: _legend[1], // type: 'line', // data: calculatema(data,5), // smooth: true, // linestyle: { // normal: {opacity: 0.5}, // } // }, // { // name: _legend[2], // type: 'line', // data: calculatema(data,10), // smooth: true, // linestyle: { // normal: {opacity: 0.5} // } // }, // { // name: _legend[3], // type: 'line', // data: calculatema(data,20), // smooth: true, // linestyle: { // normal: {opacity: 0.5} // } // }, // { // name: _legend[4], // type: 'line', // data: calculatema(data,30), // smooth: true, // linestyle: { // normal: {opacity: 0.5} // } // }, ] }; }