封装好以后在页面引用这个js然后直接调用这个js里面的方法往里面传参即可,有一些特殊的属性如果少部分跟这里不一样或这里面没有可以自行根据Echarts官网和需求写一个即可
var echartsTheme;
$(document).ready(function(){
//setEchartsTheme("infographic");
setEchartsTheme("shine");//设置主题
});
function setEchartsTheme(inTheme){
echartsTheme = inTheme;
}
function echartShow(option,container){
try{
if(echartsOptionDefault != undefined)
setChartsDefault(echartsOptionDefault,option);
}catch(e){}
if(echartsTheme==undefined && option.color==undefined){
option["color"] = [
"#00e2fd",
"#e9c229",
"#11d67c",
"#fe6c84",
"#fff600",
"#7e71ff",
"#008bfe",
"#f89758",
"#6e7074",
"#546570",
"#c4ccd3"
];
}
if(option.toolbox==undefined){
option["toolbox"]={show : true,
feature : {
dataView : {
show: true, readOnly: false},
magicType : {
show: true, type: ['line', 'bar','pie']},
restore : {
show: true},
saveAsImage : {
show: true}
}
};
}
var dom = document.getElementById(container);
dom.removeAttribute("_echarts_instance_");
var myChart;
if(echartsTheme==undefined){
myChart = echarts.init(dom);
}else{
myChart = echarts.init(dom,echartsTheme);
}
myChart.setOption(option, true);
window.onresize = myChart.resize;
return myChart;
}
function setChartsDefault( data, inOption ) {
if ( inOption == undefined ) {
inOption=data;
} else if ( data.constructor == Array ) {
for ( var i=0; i<inOption.length; i++ ) {
setChartsDefault( data[0], inOption[i] );
}
//return ;
} else {
for ( var key