在作项目的过程当中,总会遇到这样或者那样的bug,这个时候就要看本身的动手能力有多强了,着手解决了一个bug以后,整我的都感受很开心,端午下班以前遇到了一个小问题,echarts散点图鼠标划过散点的时候,没有显示从后台拿过来的数据,今天一看,原来是忘记写代码了,没有写返回数据,又怎么会返回须要的信息而且展现在前端界面?javascript
紧跟着上一篇进行完善,本篇文章主要是解决echarts散点图鼠标划过散点显示信息的问题,篇幅较短,大约须要两分钟读完。html
只须要在option里面写上返回须要的信息代码。前端
tooltip: { /*返回须要的信息*/ formatter: function(param) { var value = param.value; return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 16px;padding-bottom: 7px;margin-bottom: 7px;"> ' + value[2] + '(' + value[1] + ')' + '</div>'; } },
tooltip: { /*返回须要的信息*/ formatter: function(param) { var value = param.value; return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 16px;padding-bottom: 7px;margin-bottom: 7px;"> ' + value[2] + '(' + value[1] + ')' + '</div>'; } },
改造后的效果以下,echarts散点图鼠标划过散点显示翻身的次数。java
示例完整代码以下:jquery
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>五分钟上手之散点图</title>
<!-- 引入 echarts.js -->
<script src="js/echarts.min.js"></script>
<script src="js/jquery-1.11.3.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具有大小(宽高)的Dom -->
<div style="height: 500px;width: 1000px;" id="Scatter"></div>
<script type="text/javascript"> $(document).ready(function() { var MyScatter = echarts.init(document.getElementById('Scatter')); var data = [ ['2012-03-01', 1, "翻身" ], [ '2013-06-01', 2, "没翻身" ], [ '2014-03-02', 3, "翻身" ], [ '2015-03-03', 5, "翻身" ],[ '2016-03-04', 7, "翻身" ] ]; var textStyle = { color: '#333', fontStyle: 'normal', fontWeight: 'normal', fontFamily: '微软雅黑', fontSize: 14, }; option = { tooltip: { /*返回须要的信息*/ formatter: function(param) { var value = param.value; return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 16px;padding-bottom: 7px;margin-bottom: 7px;"> ' + value[2] + '(' + value[1] + ')' + '</div>'; } }, xAxis: { type: 'time', name: '时间轴', }, yAxis: { type: 'value', name: '次数值', max: 13, min: 0, }, series: [{ name: '', data: data, type: 'scatter', symbolSize: 40 }] }; MyScatter.setOption(option); }); </script>
</body>
</html>
注:
程序员
关注「编程微刊」公众号 ,在微信后台回复「领取资源」,获取IT资源300G干货大全。原文做者:祈澈姑娘技术博客:https://www.jianshu.com/u/05f416aefbe1
90后前端妹子,爱编程,爱运营,爱折腾。
坚持总结工做中遇到的技术问题,坚持记录工做中所所思所见,欢迎你们一块儿探讨交流。编程
公众号回复“1”,拉你进程序员技术讨论群.微信