Echarts 图表使用(一)

折线图和柱状图对比

通过点击Echart 图表右上角的 色块 可以控制对应图表的显隐。但在多条柱状图中,对应的图形复杂(可以调整柱状图之间的距离解决),不符合图表直观清晰的特征,所以通过改写成折线图的方式更有利。在只有两支柱状图时,使用柱状图较好。

多条折线图

多柱状图

2. 多图表展示

一般一个option 对应一张图表,但是也可以将多张图表通过一个option 展示

多图表


var edu = ['专科', '本科', '硕士', '博士'
];
var eduS = [200, 120, 256, 250];

var city = ['北京', '上海', '深圳', '广州', '杭州',
    '丰富', '浮点', '佛山', '长沙', '成都'
];
var cityS = [200, 120, 256, 250, 200, 180, 200, 190, 124, 200];

var comp = ['100-200', '200-300', '300-500', '<100'
];
var compS = [200, 120, 256, 250];

var exper = ['1年经验', '2年经验', '3年经验', '4年经验', '5年经验'
];
var experS = [250, 200, 180, 190, 200];
var colors = ['#96d668', '#01babc', '#1a98f8', '#7049f0'];

option = {
    backgroundColor: "#2d3548",
    title: [{
            text: "学历与岗位工资",
            left: "70%",
            textStyle: {
                color: "#fff",
                fontSize: "14"
            }
        }, {
            left: "25%",
            text: "城市与岗位工资",
            textStyle: {
                color: "#fff",
                fontSize: "14"
            }
        },
        {
            text: "公司规模与岗位工资",
            left: "70%",
            top: "52%",
            textStyle: {
                color: "#fff",
                fontSize: "14"
            }
        }, {
            left: "25%",
            top: "52%",
            text: "工作经验与岗位工资",
            textStyle: {
                color: "#fff",
                fontSize: "14"
            }
        }
    ],
    grid: [{
            x: '8%',
            y: '8%',
            width: '40%',
            height: "40%",
            containLabel: true
        },
        {
            x2: '8%',
            y: '8%',
            width: '40%',
            height: "40%",
            containLabel: true
        },
        {
            x: '8%',
            y2: '0',
            width: '40%',
            height: "40%",
            bottom: "2%",
            containLabel: true
        },
        {
            x2: '8%',
            y2: '0',
            width: '40%',
            height: "40%",
            bottom: "2%",
            containLabel: true
        },
    ],
    tooltip: {
        formatter: '{b}:<br/> {c}'
    },
    xAxis: [
        {
            gridIndex: 0,
            type: 'category',
            boundaryGap: true, //坐标轴两边留白
            data: edu,
            axisLabel: { //坐标轴刻度标签的相关设置。
                interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
                margin: 15,
                textStyle: {
                    color: '#ddd',
                    fontStyle: 'normal',
                    fontFamily: '微软雅黑',
                    fontSize: 12,
                }
            },
            axisTick: {
                show: false,
            },
            axisLine: { //坐标轴轴线相关设置
                lineStyle: {
                    color: '#ddd',
                    opacity: 0.2
                }
            },
            splitLine: {
                show: false,
            }
        },
        {
            gridIndex: 1,
            type: 'category',
            boundaryGap: true, //坐标轴两边留白
            data: comp,
            axisLabel: { //坐标轴刻度标签的相关设置。
                interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
                margin: 15,
                textStyle: {
                    color: '#ddd',
                    fontStyle: 'normal',
                    fontFamily: '微软雅黑',
                    fontSize: 12,
                }
            },
            axisTick: { //坐标轴刻度相关设置。
                show: false,
            },
            axisLine: { //坐标轴轴线相关设置
                lineStyle: {
                    color: '#ddd',
                    opacity: 0.2
                }
            },
            splitLine: { //坐标轴在 grid 区域中的分隔线。
                show: false,
            }
        },
        {
            gridIndex: 2,
            type: 'category',
            boundaryGap: true, //坐标轴两边留白
            data: exper,
            axisLabel: { //坐标轴刻度标签的相关设置。
                interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
                margin: 15,
                textStyle: {
                    color: '#ddd',
                    fontStyle: 'normal',
                    fontFamily: '微软雅黑',
                    fontSize: 12,
                }
            },
            axisTick: { //坐标轴刻度相关设置。
                show: false,
            },
            axisLine: { //坐标轴轴线相关设置
                lineStyle: {
                    color: '#ddd',
                    opacity: 0.2
                }
            },
            splitLine: { //坐标轴在 grid 区域中的分隔线。
                show: false,
            }
        },
        {
            gridIndex: 3,
            type: 'category',
            boundaryGap: true, //坐标轴两边留白
            data: city,
            axisLabel: { //坐标轴刻度标签的相关设置。
                interval: 0, //设置为 1,表示『隔一个标签显示一个标签』
                margin: 15,
                textStyle: {
                    color: '#ddd',
                    fontStyle: 'normal',
                    fontFamily: '微软雅黑',
                    fontSize: 12,
                }
            },
            axisTick: { //坐标轴刻度相关设置。
                show: false,
            },
            axisLine: { //坐标轴轴线相关设置
                lineStyle: {
                    color: '#ddd',
                    opacity: 0.2
                }
            },
            splitLine: { //坐
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值