数据可视化echarts实现在柱状图中插入标记点和标记线

 一:echarts是什么?

一个纯JavaScript图表库。ECharts,缩写来自Enterprise Charts,商业级数据图表,一个纯Javascript的图表库,可以流畅的运行在PC和移动设备上,兼容当前绝大部分浏览器(IE6/7/8/9/10/11,chrome,firefox,Safari等),底层依赖轻量级的Canvas类库ZRender,提供直观,生动,可交互,可高度个性化定制的数据可视化图表。创新的拖拽重计算、数据视图、值域漫游等特性大大增强了用户体验,赋予了用户对数据进行挖掘、整合的能力。

二:使用步骤:

1.引入echarts.js插件

<!DOCTYPE html>
<html>
 
<head>
	<meta charset="utf-8">
	<script src="echarts.js"></script>
</head>

2.设置标题格式:颜色,大小,位置

<div id="main" style="width: 900px; height: 600px"></div>
	<script type="text/javascript">
		var myChart = echarts.init(document.getElementById("main"));
        mytextStyle = {
            color: "red",
            fontWeight: "",
            fontSize: 20,
        };
		var option = {
            title:{
                show:true,
                text:'销售经理能力对比分析',
                textStyle: mytextStyle,
                left:'center',
            },

3 .设置提示框组件 

tooltip:{
                trigger: 'axis',
                axisPointer:{
                    type: 'shadow',
                    label: {
                        show: true
                    }
                }
            },

4.设置工具栏

toolbox:{
                show: true,
                feature:{
                    mark: { show: true },
                    dataView: { show: true, readOnly: false },
                    magicType: { show: true, type: ['line', 'bar', 'stack', 'tiled'] },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
            },

5. 插入图例 

 legend:{
                data: ['王斌', '刘倩','袁波'],
                itemGap: 5,
                left:'left',
                top:'25',
                itemGap: 25,
            },

6.设置直角坐标系内网格,x,y轴

 grid:{
                top: '12%',
                left: '1%',
                right: '10%',
                containLabel: true
            },
            xAxis:[
                {
                    type: 'category',
                    data:['销售','沟通','服务','协作','培训','组织']
                }
            ],
            yAxis:[
                {
                    type: 'value',
                }
            ],
            dataZoom:{
                show: true, 
                realtime: true,
                start: 20, 
                end: 40
            },

7.设置组内数据(添加标记点和标记线)

 series:[
        {
            name:'王斌',
            type:'bar',
            data:[87.5,87.5,90,91.25,85,87.5],
            itemStyle:{
                color:'#dd6b66'
            },
            markPoint:{  //设置标记点
					data: [
						{
							type: 'min', name: '最小值', symbol: 'arrow', symbolSize: 20,
							itemStyle: {  //设置标记点的样式
								normal: { color: 'blue' }
							},
						},
					],
				},
        },
     
				
        {
            name:'刘倩',
            type:'bar',
            data:[90,88.75,85,87.5,88.75,91.25],
            itemStyle:{
                color:'#759aa0'
         },
         markPoint:{  //设置标记点
					data: [

						{
							type: 'min', name: '最小值', symbol: 'arrow', symbolSize: 20,
							itemStyle: {  //设置标记点的样式
								normal: { color: 'blue' }
							},
						},
					],
				},
				markLine:{  //设置标记线
					data: [
						{
							type: 'average', name: '平均值',
							itemStyle:  //设置标记点的样式
							{
								normal: { borderType: 'dotted', color: 'darkred' }
							},
						}],
                        lineStyle:{
                            type:"soild"
                        }
				},
            },
        {
            name:'袁波',
            type:'bar',
            data:[92.5,91.25,88.75,92.5,91.25,88.75],
            itemStyle:{
                color:'#e69d87'
         },
         markPoint:{  //设置标记点
					data: [
						{
							type: 'max', name: '最大值', symbol: 'diamond', symbolSize: 25,
							itemStyle: {  //设置标记点的样式
								normal: { color: 'red' }
							},
						},
					],
				},
				markLine:{  //设置标记线
					data: [
						{
							type: 'average', name: '平均值',
							itemStyle:  //设置标记点的样式
							{
								normal: { borderType: 'dotted', color: 'darkred' }
							},
						}],
				},
        },
        
      ],

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

在代码里下毒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值