修改左侧的tooltip的内容,添加formatter函数,循环将各个值拼接成一个字符串返回
tooltip: { formatter: function(param) { /*console.log(1); console.log(JSON.stringify(param)); console.log(param.name); */ return '<div style=" "> '+ param.name + "<br>" + param.value + "<br>" '</div>'; } },
例子如下
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>五分钟上手之折线图</title> <!-- 引入 echarts.js --> <script src="https://cdn.bootcss.com/echarts/4.2.1-rc1/echarts.min.js"></script> <script src="https://cdn.bootcss.com/jquery/3.4.0/jquery.min.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 myChart.setOption({ title: { text: '近七日收益' }, tooltip: { formatter: function(param) { console.log(JSON.stringify(param)); console.log(param.name); return '<div style=" "> '+ param.name + "<br>" + param.value + "<br>" '</div>'; } }, legend: { data: ['近七日收益'] }, grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true }, toolbox: { feature: { saveAsImage: {} } }, xAxis: { type: 'category', boundaryGap: false, data: ["1", "2", "3", "4", "5"] }, yAxis: { type: 'value' }, series: [ { name: '近七日收益', type: 'line', stack: '总量', data: ["1", "4", "3", "1", "5"] } ] }); // 异步加载数据 /* $.get('data.json').done(function (data) { // 填入数据 myChart.setOption({ xAxis: { data: data.categories }, series: [{ // 根据名字对应到相应的系列 name: '销量', data: data.data }] });});*/ </script> </body> </html>