console
// 柱状图
var myChart = echarts.init(document.getElementById('bar01'));
// 指定图表的配置项和数据
const dataCount = 1e4;
const data = generateData(dataCount);
option = {
title: {
text: echarts.format.addCommas(dataCount) + ' Data',
left: 10
},
toolbox: {
feature: {
dataZoom: {
yAxisIndex: false
},
saveAsImage: {
pixelRatio: 2
}
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
}
},
grid: {
bottom: 90
},
dataZoom: [
{
type: 'inside'
},
{
type: 'slider'
}
],
xAxis: {
data: data.categoryData,
silent: false,
splitLine: {
show: false
},
splitArea: {
show: false
}
},
yAxis: {
splitArea: {
show: false
}
},
series: [
{
type: 'line',
data: data.valueData,
// Set `large` for large data amount
step: null,
symbol: 'emptyCircle',
lineStyle: null,
connectNulls: true,
showAllSymbol: true,
large: true,
largeThreshol: 1000,
progressive: 1000,
progressiveThreshold: 1000
}
]
};
function generateData(count) {
let baseValue = Math.random() * 1000;
let time = +new Date(2011, 0, 1);
let smallBaseValue;
function next(idx) {
smallBaseValue =
idx % 30 === 0
? Math.random() * 700
: smallBaseValue + Math.random() * 500 - 250;
baseValue += Math.random() * 20 - 10;
return Math.max(0, Math.round(baseValue + smallBaseValue) + 3000);
}
const categoryData = [];
const valueData = [];
for (let i = 0; i < count; i++) {
categoryData.push(
echarts.format.formatTime('yyyy-MM-dd\nhh:mm:ss', time, false)
);
valueData.push(next(i).toFixed(2));
time += 1000;
}
return {
categoryData: categoryData,
valueData: valueData
};
}
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
//Ajax动态改变数据
/*setInterval(function () {
$.ajax({
type: "post",
url: "",
//data: {arg1:'',arg2: ''},
dataType: "json",
success: function (data) {
myChart.setOption({
series: [{
data: data
}]
});
}
});
}, 1000);*/
<script src="https://cdn.bootcss.com/jquery/2.2.3/jquery.js"></script>
<script src="https://cdn.bootcss.com/echarts/3.5.4/echarts.js"></script>
<div id="bar01" style="width:600px;height:400px;margin-top:10px;"></div>