在编写一个echarts时先要将其模块化,如下:
require.config({ paths:{ 'echarts' : 'http://echarts.baidu.com/build/echarts', 'echarts/chart/bar' : 'http://echarts.baidu.com/build/echarts' } }); require( [ 'echarts', 'echarts/chart/line' ], //回调函数 DrawEChart //这里是调用一个函数用于绘制图表 );
DrawEChart注意这个函数,在之后就可以在外面定义这个function的内容,即绘制图表
在百度的demo中只给出了option,将其放入到function中即可
function DrawEChart(ec) { var chartContainer = document.getElementById("main"); var myChart = ec.init(chartContainer); myChart.setOption({
//写option的内容 )}; }
id还没有尝试传值进去,后期进行尝试
接下来关于两个属性的理解:
toolbox: { show : true, feature : { mark : {show: true}, //辅助线的开关 dataView : {show: true, readOnly: false},//数据视图readOnly默认true是只读,改为false可以编辑 magicType : {show: true, type: ['line', 'bar']},//动态类型切换 restore : {show: true},//还原功能 saveAsImage : {show: true,title:'保存为图片',type:'png',lang:['点击保存']}//保存为图片 } }, calculable : true, //是否启用拖拽重计算特性,默认是关闭的