Ehcarts 清空上一次的数据
初始化echarts
//初始化
var chartDom = document.getElementById('char');
var myChart = echarts.init(chartDom);
option = {
color: ['#2995db', '#e43810', '#beb113', '#10e41f', '#FFBF00'],
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
label: {
backgroundColor: '#6a7985'
}
}
},
legend: {
top: '1%',
data: [],
icon: "circle",//形状 类型包括 circle,rect,line,roundRect,triangle,diamond,pin,arrow,none
itemWidth: 6, // 设置宽度
itemHeight: 6, // 设置高度
textStyle:{
color:"#fff"
}
},
xAxis:{
type: 'category',
boundaryGap: false,
data: [],
axisLabel: {
show: true,
textStyle: {
color: '#fff'
}
},
},
yAxis:{
type: 'value',
splitLine:{
show:false
},
axisLabel: {
show: true,
textStyle: {
color: '#fff'
}
},
},
grid:{
x:50,
y:30,
x2:20,
y2:20
},
series: [
]
};
myChart.setOption(option);
AJAX请求后台改变echars内容
function xxx(name){
$.ajax({
url: xxx,
headers: {
'Access-Control-Allow-Origin': "*",
},
contentType: 'application/x-www-form-urlencoded',
dataType: "json",
data:{
name:name
},
cache: false,
type:"POST",
success: function(data) {
//先调用clear()方法
myChart.clear();
//clear()清空当前实例,会移除实例中所有的组件和图表。不加这行F12 会报错
myChart.setOption(option);
myChart.setOption({
legend:{
data:data,
},
xAxis:{
data:data
},
series:series
});
}
})
}