初始化echarts,添加echarts.js:
<script src="js/echarts/echarts.js"></script>
初始化代码:
function drawLine(options) {
var __ec = null;
var __target = null;
var __option = options;
var __unit = __option.unit;
var Option = {
tooltip: {
trigger: 'axis'
},
title : __option.title ? __option.title : null,
toolbox: {
show: true,
feature: {
restore: {show: true},
saveAsImage: {show: true}
},
orient: "vertical"
},
calculable: true,
xAxis: [
{
type: 'category',
boundaryGap: false,
data: __option.lables
}
],
yAxis: [
{
type:'value',
name:__option.unit,
splitNumber:__option.splitNumber?__option.splitNumber:4,
nameTextStyle:{
color:'#373737',
fontSize:12,
fontWeight:'normal'
}
}
],
series: __option.series,
grid: {x: "10%", y: "15%", height: "70%"}
};
if(options.feature) {
$.extend(Option.toolbox.feature, options.feature);
}
require.config({
paths: {
"echarts": "js/echarts/"
}
});
require(
[
"echarts",
"echarts/chart/line"
],
function (ec) {
__ec = ec;
__target = $("#" + options.target).get(0);
myChart = __ec.init(__target);
myChart.setOption(Option, true);
}
);
}