官方文档地址:5 分钟上手 ECharts
完全版:echarts/dist/echarts.js,体积最大,包含所有的图表和组件,所包含内容参见:echarts/echarts.all.js。 常用版:echarts/dist/echarts.common.js,体积适中,包含常见的图表和组件,所包含内容参见:echarts/echarts.common.js。 精简版:echarts/dist/echarts.simple.js,体积较小,仅包含最常用的图表和组件,所包含内容参见:echarts/echarts.simple.js。
文档->数语速查手册
文档->配置项手册
效果:见右上角工具栏
在数据视图中,用户可以动态修改数据。可以resotre还原。 tooltip:浮动提示层的除法选项markline标记线 markpoint标记点
可以设置不同区域颜色、动态仪表指针动画效果
代码示例(无法选择区域放大,会报错。。)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>echarts</title> <!-- <script src="/static/js/jquery-1.7.2.min.js" charset="UTF-8"></script> --> <script src="static/js/echarts.js"></script> </head> <body> <!-- 为ECharts准备一个具备大小(宽高)的Dom --> <div id="main" style="width: 600px;height:400px;"></div> <script type="text/javascript"> var a = 123; //测试变量作用域 // 基于准备好的dom,初始化echarts实例 var myChart = echarts.init(document.getElementById('main')); // 指定图表的配置项和数据 var option = { //标题 title: { text: '温度-降水量示例' }, tooltip: { show: true, trigger: 'axis', axisPointer: { type: 'cross', animation: false, label: { show: true, backgroundColor: '#0D4286' } } }, toolbox: { show: true, feature: { mark: { show: true }, dataZoom: { //yAxisIndex: 'none' yAxisIndex: 0 }, dataView: { show: true, readOnly: false, }, magicType: { show: true, type: ['line', 'bar'] }, restore: { show: true, }, saveAsImage: { show: true, } } }, //图例,可以通过点击选择显示和隐藏某组数据 legend: { data: ['降水量', '平均温度1', '平均温度2'] }, dataZoom: [{ id: 'dataZoomX', show: true, realtime: true, orient: "horizontal", start: 0, end: 50, dataBackground: { lineStyle: { color: '#95BC2F' }, /*areaStyle: { color: '#95BC2F', opacity: 1, }*/ }, // backgroundColor:'#d' textStyle: { color: "#ffffff" }, }, // { // id: 'dataZoomY1', // width: 15, // type: 'slider', // yAxisIndex: [0], // orient: "vertical", // realtime: true, // start: 0, // end: 100 // }, ], //x轴值 xAxis: { type: 'category', axisLabel: { rotate: 45, textStyle: { fontSize: '8' } }, data: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15] }, //如果不定义y轴,会根据数据自动生成y轴 yAxis: [{ type: 'value', name: '水量', min: 0, max: 120, interval: 50, axisLabel: { formatter: '{value}毫升' } }, { type: 'value', name: '温度', min: 0, max: 27, interval: 5, axisLabel: { formatter: '{value}度' } }], //传入的数据(可以是多个数组) series: [{ name: '降水量', type: 'line', yAxisIndex: 0, data: [80, 89, 85, 84, 76, 76, 75, 80, 92, 95, 105, 106, 107, 108, 109, 120] }, { name: '平均温度1', type: 'line', yAxisIndex: 1, data: [10, 12, 14, 15, 14, 18, 20, 20, 19, 19, 18, 18] }, { name: '平均温度2', type: 'line', yAxisIndex: 1, data: [11, 13, 15, 16, 18, 20, 20, 21, 20, 22, 21, 23] }, ] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); </script> </body> </html> </html>参考:https://www.jianshu.com/p/fcb3ccc7a27a(评论区)
如果先改div的话canvas的宽度会很宽,页面放不下。后来想着可以先canvas绘图,再改canvas大小,使其适应页面。再后来,发现直接修改containLabel即可。。
或者参考:百度经验-echarts 如何修改canvas的宽高