官网地址:https://echarts.apache.org/examples/zh/index.html
1. 柱状图
var option = {
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'shadow'
},
// 修改鼠标移到柱子上时,显示的内容
formatter: function (params) {
console.log(params);//打印断点,会看到自己想要的后台数据
return '发电量:' + params[0].value+'MW';
}
},
grid: {
left: '3%',
right: '4%',
bottom: '3%',
containLabel: true
},
xAxis: [
{
type: 'category',
data: xAxis_data,
axisTick: {
alignWithLabel: true
},
axisLabel: {
textStyle: {
color: '#000000', //更改坐标轴文字颜色
fontSize: 15 //更改坐标轴文字大小
},
margin: 10 //X轴线与文字之间的距离
},
axisLine: {
lineStyle: {
color: '#000000' //更改坐标轴颜色
}
}
}
],
yAxis: [
{
type: 'value',
axisLabel: {
textStyle: {
color: '#ADFF2F', //更改坐标轴文字颜色
fontSize: 16, //更改坐标轴文字大小
fontWeight: 300 //字体的粗细
}
},
axisLine: {
lineStyle: {
color: '#ADFF2F' //更改坐标轴颜色
}
},
//修改横向网格线的颜色、宽度、线的类型
splitLine: {
show: true,
lineStyle: {
color: ['#000000'],
width: 1,
type: 'solid'
}
}
}
],
series: [
{
name: '发电量',
type: 'bar',
barWidth: '60%',
data: series_data,
//柱子的颜色
itemStyle: {
normal: {
color: '#ADFF2F'
}
},
}
]
};
// 基于准备好的dom,初始化echarts图表
var myChartBar = echarts.init(document.getElementById("chart"));
// 过渡---------------------
myChartBar.showLoading({
text: '读取数据中...' //loading话术
});
myChartBar.setOption(option);
myChartBar.dispatchAction({
type: "highlight",
seriesIndex: 0,
dataIndex: 0
}); //设置默认选中高亮部分
myChartBar.hideLoading();