<html>
<head>
<meta charset="utf-8" />
<title>ECharts</title>
<!-- 引入刚刚下载的 ECharts 文件 -->
<script src="echarts-5.2.1/dist/echarts.min.js"></script>
</head>
<body>
<!-- 为 ECharts 准备一个定义了宽高的 DOM -->
<div id="main" style="width: 600px;height:400px;"></div>
<script type="text/javascript">
// 基于准备好的dom,初始化echarts实例
data_y = [5, 20, 36, 10, 10, 20];
data_x = ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'];
var myChart = echarts.init(document.getElementById('main'));
// 指定图表的配置项和数据
var option = {
title: {
text: 'ECharts 入门示例'
},
grid:{ //显示网格
show:true
},
tooltip: {
show:true //提示框组件
},
legend: {
data: ['销量'] //显示图例
},
xAxis: {
type:'value',
// axisLine: {
// symbol:'arrow',
// lineStyle: {
// type: 'dashed'
// }
// }
axisLine: {
show:true, //设置x轴是否可见
symbol: ['none', 'triangle'], //只在末端显示箭头
symbolOffset: 8, // 偏移距离
symbolSize: [10, 15], // 箭头宽高
lineStyle: {
color: '#054E8C', // 坐标轴颜色
},
}
},
yAxis: {
type:'category',
show:true,
data: data_x,
axisLine: {
symbol: ['none', 'triangle'], //只在末端显示箭头
symbolOffset: 8, // 偏移距离
symbolSize: [10, 15], // 箭头宽高
lineStyle: {
color: '#054E8C', // 坐标轴颜色
},
}
},
series: [
{
name: '销量',
type: 'bar',
stack: 'samestack',
data:data_y,
markLine:{ //设置标线
tooltip: {
show:false //提示框组件
},
symbol:['none','none'], //清除标线两端的样式,可以这样显示末端的箭头或者清除末端的箭头
data:[{
type:"average",
name:'平均值',
lineStyle:{
cap:'butt', //设置标线末端的样式,但是这样清除不了末端默认的箭头
type:'solid'
}
}],
label:{
//这里是设置标线的标签显示,包括标线的文本内容,文本的样式等
// padding:[-13,-20,15,-40],
show:true ,
formatter:'{a}{b}的值是{c}'
},
itemStyle:{
// color: '#F43368'
}
},
label:{
show:true,
// data:data_y,
formatter:'{b}的值是{c}', //设置柱状图的标签显示文字
// rotate:90,
fontStyle:"oblique"
},
// labelLine:{
// show:true,
// lineStyle:{
// color:"#b",
// width:1,
// type:'solid'
// }
// },
itemStyle:{
// color: '#F43368',
barBorderRadius: [0, 20, 20, 0], // (顺时针左上,右上,右下,左下)
}
},
{
//name: 'Video Ad',
type: 'bar',
stack: 'samestack', //柱状图的堆叠样式
// barWidth: 5, //柱图宽度
data: ['20','20','20','20','20','20'],
itemStyle: {
normal: {
color:"#ff3333", //给柱状图添加颜色
label: {
show: true,
// formatter: item => {
// // return left_value+'%'
// return item.data + '%'
// }
}
}
},
},
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
</script>
</body>
</html>
echarts图表
最新推荐文章于 2024-06-26 11:56:44 发布