1. 程式人生 > >Echarts自定義tootips

Echarts自定義tootips

row enter tip edit mat ack 坐標軸 graphic tick

由於業務需求,現在要自定義tootips;

設計稿如下:

技術分享圖片

代碼如下:

app.title = ‘坐標軸刻度與標簽對齊‘;
var str1 = "top:-20px;border:0px solid #000;position:relative;width:100px;height:60px;line-height:60px;background:rgba(50,50,50,0.7);;border-radius:4px;text-align:center;";
var arrow="position:absolute;color:rgba(50,50,50,0.7);width: 0px;height:0px;height:0px;line-height: 0px;border-width: 10px 15px 0;border-style: solid dashed dashed dashed;border-left-color: transparent;border-right-color: transparent;bottom: -10px;right: 50%;margin-right:-15px";
option 
= { color: [‘#3398DB‘], tooltip : { trigger: ‘item‘, axisPointer : { // 坐標軸指示器,坐標軸觸發有效 type : ‘shadow‘ // 默認為直線,可選為:‘line‘ | ‘shadow‘ }, position:"top", formatter:function(params) { return "<div style=‘"+str1+"‘><div style=‘"+arrow+"‘></div>"+params.value+"</div>"; }, backgroundColor:
‘transparent‘ }, grid: { left: ‘3%‘, right: ‘4%‘, bottom: ‘3%‘, containLabel: true }, xAxis : [ { type : ‘category‘, data : [‘13:00‘, ‘13:05‘, ‘13:10‘, ‘13:15‘, ‘13:20‘, ‘13:25‘, ‘13:30‘,‘13:35‘,‘13:40‘,‘13:45‘,‘13:50‘,‘13:55‘], axisTick: { alignWithLabel:
true } } ], yAxis : [ { // type : ‘category‘, // data : [‘10‘,‘20‘,‘30‘,‘40‘], axisTick: { alignWithLabel: true } } ], series : [ { name:‘直接訪問‘, type:‘bar‘, barWidth: ‘40%‘, data:[1, 3, 2, 3, 4, 2, 1,3,3,2,3,2] }, ], label: { normal: { show: true, position: ‘top‘, formatter: ‘{c}‘ } }, itemStyle: { normal: { color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{ offset: 0, color: ‘rgba(17, 168,171, 1)‘ }, { offset: 1, color: ‘rgba(17, 168,171, 0.1)‘ }]), shadowColor: ‘rgba(0, 0, 0, 0.1)‘, shadowBlur: 10 } } };

更多 :http://gallery.echartsjs.com/editor.html?c=xB1DgDmtmb

Echarts自定義tootips