Echarts 柱状图配置详解

柱状图比如做成如下所示图:

所有的基本配置如下:

// 指定图表的配置项和数据
var option = {
  // ----  标题 -----
  title: {
    text: ‘主标题‘,
    textStyle: {
      color: ‘red‘
    },
    subtext: ‘副标题‘,
    subtextStyle: {
      color: ‘blue‘
    },
    padding: [0, 0, 10, 100]  // 位置
  },
  // ---- legend ----
  legend: {
    type: ‘plain‘,  // 图列类型,默认为 ‘plain‘
    top: ‘1%‘,  // 图列相对容器的位置 top\bottom\left\right
    selected: {
      // ‘销量‘: true  // 图列选择,图形加载出来会显示选择的图列,默认为true
    },
    textStyle: {  // 图列内容样式
      color: ‘#fff‘,  // 字体颜色
      backgroundColor: ‘black‘  // 字体背景色
    },
    tooltip: {  // 图列提示框,默认不显示
      show: true,
      color: ‘red‘
    },
    data: [   // 图列内容
      {
        name: ‘销量‘,
        icon: ‘circle‘,
        textStyle: {
          color: ‘red‘,  // 单独设置某一个图列的颜色
          backgroundColor: ‘#fff‘ // 单独设置某一个图列的字体背景色
        }
      }
    ]
  },
  // ---  提示框 ----
  tooltip: {
    show: true,   // 是否显示提示框,默认为true
    trigger: ‘item‘, // 数据项图形触发
    axisPointer: {   // 指示样式
      type: ‘shadow‘,
      axis: ‘auto‘
    },
    padding: 5,
    textStyle: {   // 提示框内容的样式
      color: ‘#fff‘
    }
  },
  // ---- gird区域 ---
  gird: {
    show: false,    // 是否显示直角坐标系网格
    top: 80,  // 相对位置 top\bottom\left\right
    containLabel: false, // gird 区域是否包含坐标轴的刻度标签
    tooltip: {
      show: true,
      trigger: ‘item‘,   // 触发类型
      textStyle: {
        color: ‘#666‘
      }
    }
  },
  //  ------  X轴 ------
  xAxis: {
    show: true,  // 是否显示
    position: ‘bottom‘,  // x轴的位置
    offset: 0, // x轴相对于默认位置的偏移
    type: ‘category‘,   // 轴类型, 默认为 ‘category‘
    name: ‘月份‘,    // 轴名称
    nameLocation: ‘end‘,  // 轴名称相对位置
    nameTextStyle: {   // 坐标轴名称样式
      color: ‘red‘,
      padding: [5, 0, 0, -5]
    },
    nameGap: 15, // 坐标轴名称与轴线之间的距离
    nameRotate: 0,  // 坐标轴名字旋转
    axisLine: {       // 坐标轴 轴线
      show: true,  // 是否显示
      symbol: [‘none‘, ‘arrow‘],  // 是否显示轴线箭头
      symbolSize: [8, 8], // 箭头大小
      symbolOffset: [0, 7],  // 箭头位置
      // ------   线 ---------
      lineStyle: {
        color: ‘blue‘,
        width: 1,
        type: ‘solid‘
      }
    },
    axisTick: {    // 坐标轴 刻度
      show: true,  // 是否显示
      inside: true,  // 是否朝内
      length: 3,     // 长度
      lineStyle: {   // 默认取轴线的样式
        color: ‘red‘,
        width: 1,
        type: ‘solid‘
      }
    },
    axisLabel: {    // 坐标轴标签
      show: true,  // 是否显示
      inside: false, // 是否朝内
      rotate: 0, // 旋转角度
      margin: 5, // 刻度标签与轴线之间的距离
      color: ‘red‘  // 默认取轴线的颜色
    },
    splitLine: {    // gird区域中的分割线
      show: false,  // 是否显示
      lineStyle: {
        // color: ‘red‘,
        // width: 1,
        // type: ‘solid‘
      }
    },
    splitArea: {    // 网格区域
      show: false  // 是否显示,默认为false
    },
    data: [‘1月‘, ‘2月‘, ‘3月‘, ‘4月‘, ‘5月‘, ‘6月‘, ‘7月‘, ‘8月‘, ‘9月‘, ‘10月‘, ‘11月‘, ‘12月‘]
  },
  //   ------   y轴  ----------
  yAxis: {
    show: true,  // 是否显示
    position: ‘left‘, // y轴位置
    offset: 0, // y轴相对于默认位置的偏移
    type: ‘value‘,  // 轴类型,默认为 ‘category’
    name: ‘销量‘,   // 轴名称
    nameLocation: ‘end‘, // 轴名称相对位置value
    nameTextStyle: {    // 坐标轴名称样式
      color: ‘#fff‘,
      padding: [5, 0, 0, 5]  // 坐标轴名称相对位置
    },
    nameGap: 15, // 坐标轴名称与轴线之间的距离
    nameRotate: 270,  // 坐标轴名字旋转

    axisLine: {    // 坐标轴 轴线
      show: true,  // 是否显示
      //  -----   箭头 -----
      symbol: [‘none‘, ‘arrow‘],  // 是否显示轴线箭头
      symbolSize: [8, 8],  // 箭头大小
      symbolOffset: [0, 7], // 箭头位置

      // ----- 线 -------
      lineStyle: {
        color: ‘blue‘,
        width: 1,
        type: ‘solid‘
      }
    },
    axisTick: {      // 坐标轴的刻度
      show: true,    // 是否显示
      inside: true,  // 是否朝内
      length: 3,      // 长度
      lineStyle: {
        color: ‘red‘,  // 默认取轴线的颜色
        width: 1,
        type: ‘solid‘
      }
    },
    axisLabel: {      // 坐标轴的标签
      show: true,    // 是否显示
      inside: false,  // 是否朝内
      rotate: 0,     // 旋转角度
      margin: 8,     // 刻度标签与轴线之间的距离
      color: ‘red‘,  // 默认轴线的颜色
    },
    splitLine: {    // gird 区域中的分割线
      show: true,   // 是否显示
      lineStyle: {
        color: ‘#666‘,
        width: 1,
        type: ‘dashed‘
      }
    },
    splitArea: {     // 网格区域
      show: false   // 是否显示,默认为false
    }
  },
  //  -------   内容数据 -------
  series: [
    {
      name: ‘销量‘,      // 序列名称
      type: ‘bar‘,      // 类型
      legendHoverLink: true,  // 是否启用图列 hover 时的联动高亮
      label: {   // 图形上的文本标签
        show: false,
        position: ‘insideTop‘, // 相对位置
        rotate: 0,  // 旋转角度
        color: ‘#eee‘
      },
      itemStyle: {    // 图形的形状
        color: ‘blue‘,
        barBorderRadius: [18, 18, 0 ,0]
      },
      barWidth: 20,  // 柱形的宽度
      barCategoryGap: ‘20%‘,  // 柱形的间距
      data: [3000, 4000, 4200, 4500, 6000, 5600, 4500, 5020, 4500, 5400, 4300, 1200]
    }
  ]
};

html代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="./echarts4.x.js"></script>
    <script type="text/javascript" src="./zhuzhangtu.js"></script>
</head>
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width: 600px;height:400px;margin: 0 auto"></div>
    <script type="text/javascript">
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById(‘main‘));
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    </script>
</body>
</html>

2. 如何做折叠柱状图?

比如如下效果的:

所有的基本配置如下:

// 指定图表的配置项和数据
option = {
  title: {
    text: "",
    textStyle: {
      color: "#436EEE",
      fontSize: 17
    }
  },
  tooltip: {
    trigger: ‘axis‘,
    axisPointer: {
      type: ‘shadow‘
    }
  },
  legend: {
    data:[
      {
        name: ‘政策法规‘,
        icon: ‘circle‘,
        textStyle: {
          color: ‘red‘,  // 单独设置某一个图列的颜色
          backgroundColor: ‘#fff‘ // 单独设置某一个图列的字体背景色
        }
      },
      {
        name: ‘经办规程‘,
        icon: ‘circle‘,
        textStyle: {
          color: ‘red‘,  // 单独设置某一个图列的颜色
          backgroundColor: ‘#fff‘ // 单独设置某一个图列的字体背景色
        }
      },
      {
        name: ‘业务场景模拟‘,
        icon: ‘circle‘,
        textStyle: {
          color: ‘red‘,  // 单独设置某一个图列的颜色
          backgroundColor: ‘#fff‘ // 单独设置某一个图列的字体背景色
        }
      },
      {
        name: ‘常见问题‘,
        icon: ‘circle‘,
        textStyle: {
          color: ‘red‘,  // 单独设置某一个图列的颜色
          backgroundColor: ‘#fff‘ // 单独设置某一个图列的字体背景色
        }
      }
    ]
  },
  //x轴显示
  xAxis: {
    data: [20180611, 20180612, 20180613, 20180614, 20180615, 20180616, 20180617],
    show: true,  // 是否显示
    position: ‘bottom‘,  // x轴的位置
    offset: 0, // x轴相对于默认位置的偏移
    type: ‘category‘,   // 轴类型, 默认为 ‘category‘
    name: ‘月份‘,    // 轴名称
    nameLocation: ‘end‘,  // 轴名称相对位置
    nameTextStyle: {   // 坐标轴名称样式
      color: ‘red‘,
      padding: [5, 0, 0, -5]
    },
    nameGap: 15, // 坐标轴名称与轴线之间的距离
    nameRotate: 0,  // 坐标轴名字旋转
    axisLine: {       // 坐标轴 轴线
      show: true,  // 是否显示
      symbol: [‘none‘, ‘arrow‘],  // 是否显示轴线箭头
      symbolSize: [8, 8], // 箭头大小
      symbolOffset: [0, 7],  // 箭头位置
      // ------   线 ---------
      lineStyle: {
        color: ‘blue‘,
        width: 1,
        type: ‘solid‘
      }
    },
    axisTick: {    // 坐标轴 刻度
      show: true,  // 是否显示
      inside: true,  // 是否朝内
      length: 3,     // 长度
      lineStyle: {   // 默认取轴线的样式
        color: ‘red‘,
        width: 1,
        type: ‘solid‘
      }
    },
    axisLabel: {    // 坐标轴标签
      show: true,  // 是否显示
      inside: false, // 是否朝内
      rotate: 0, // 旋转角度
      margin: 5, // 刻度标签与轴线之间的距离
      color: ‘red‘  // 默认取轴线的颜色
    },
    splitLine: {    // gird区域中的分割线
      show: false,  // 是否显示
      lineStyle: {
        // color: ‘red‘,
        // width: 1,
        // type: ‘solid‘
      }
    },
    splitArea: {    // 网格区域
      show: false  // 是否显示,默认为false
    },
    // show: false
  },
  //   ------   y轴  ----------
  yAxis: {
    show: true,  // 是否显示
    position: ‘left‘, // y轴位置
    offset: 0, // y轴相对于默认位置的偏移
    type: ‘value‘,  // 轴类型,默认为 ‘category’
    name: ‘销量‘,   // 轴名称
    nameLocation: ‘end‘, // 轴名称相对位置value
    nameTextStyle: {    // 坐标轴名称样式
      color: ‘#fff‘,
      padding: [5, 0, 0, 5]  // 坐标轴名称相对位置
    },
    nameGap: 15, // 坐标轴名称与轴线之间的距离
    nameRotate: 270,  // 坐标轴名字旋转

    axisLine: {    // 坐标轴 轴线
      show: true,  // 是否显示
      //  -----   箭头 -----
      symbol: [‘none‘, ‘arrow‘],  // 是否显示轴线箭头
      symbolSize: [8, 8],  // 箭头大小
      symbolOffset: [0, 7], // 箭头位置

      // ----- 线 -------
      lineStyle: {
        color: ‘blue‘,
        width: 1,
        type: ‘solid‘
      }
    },
    axisTick: {      // 坐标轴的刻度
      show: true,    // 是否显示
      inside: true,  // 是否朝内
      length: 3,      // 长度
      lineStyle: {
        color: ‘red‘,  // 默认取轴线的颜色
        width: 1,
        type: ‘solid‘
      }
    },
    axisLabel: {      // 坐标轴的标签
      show: true,    // 是否显示
      inside: false,  // 是否朝内
      rotate: 0,     // 旋转角度
      margin: 8,     // 刻度标签与轴线之间的距离
      color: ‘red‘,  // 默认轴线的颜色
    },
    splitLine: {    // gird 区域中的分割线
      show: true,   // 是否显示
      lineStyle: {
        color: ‘#666‘,
        width: 1,
        type: ‘dashed‘
      }
    },
    splitArea: {     // 网格区域
      show: false   // 是否显示,默认为false
    }
  },
  tooltip: {
    position: [‘50%‘, ‘50%‘],
    padding: [5, 10]
  },
  grid: {
    left: ‘0%‘
  },
  series: [
    {
      name: "政策法规",
      type: "bar",
      stack: "业务",//折叠显示
      data: ["87.54", "88.54", "90", "91", "92", ‘95‘, ‘100‘],
      barWidth : 25,
      //显示颜色
      itemStyle:{
        normal:{color:"blue"}
      },
      label: {   // 图形上的文本标签
        show: false,
        position: ‘insideTop‘, // 相对位置
        rotate: 0,  // 旋转角度
        color: ‘#eee‘
      }
    },
   {
     name: "经办规程",
     type: "bar",
     stack: "业务",
     data: ["87.54", "88.54", "90", "91", "92", ‘95‘, ‘100‘],
     barWidth : 25,
     label: {   // 图形上的文本标签
        show: false,
        position: ‘insideTop‘, // 相对位置
        rotate: 0,  // 旋转角度
        color: ‘#eee‘
      },
     itemStyle:{
       normal:{color:"#FF8849"}
     }
   },
   {
     name: "业务场景模拟",
     type: "bar",
     stack: "业务",
     data: ["87.54", "88.54", "90", "91", "92", ‘95‘, ‘100‘],
     barWidth : 25,
     label: {   // 图形上的文本标签
        show: false,
        position: ‘insideTop‘, // 相对位置
        rotate: 0,  // 旋转角度
        color: ‘#eee‘
      },
     itemStyle:{
       normal:{color:"#3FBB49"}
     }
   },
   {
     name: "常见问题",
     type: "bar",
     stack: "业务",
     data: ["87.54", "88.54", "90", "91", "92", ‘95‘, ‘100‘],
     barWidth : 25,
     label: {   // 图形上的文本标签
        show: false,
        position: ‘insideTop‘, // 相对位置
        rotate: 0,  // 旋转角度
        color: ‘#eee‘
      },
     itemStyle:{
       normal:{color:"#56C4A5"}
     },
     barCateGoryGap: 15
   }
  ]
};

HTML代码如下:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>ECharts</title>
    <!-- 引入 echarts.js -->
    <script src="./echarts4.x.js"></script>
    <script type="text/javascript" src="./histogram.js"></script>
</head>
<body>
    <!-- 为ECharts准备一个具备大小(宽高)的Dom -->
    <div id="main" style="width: 600px;height:400px;margin: 0 auto"></div>
    <script type="text/javascript">
        // 基于准备好的dom,初始化echarts实例
        var myChart = echarts.init(document.getElementById(‘main‘));

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        myChart.on(‘click‘, function (params) {
            // 控制台打印数据的名称
            console.log(params);
        });
    </script>
</body>
</html>

原文地址:https://www.cnblogs.com/tugenhua0707/p/9380378.html

时间: 2024-08-01 04:47:50

Echarts 柱状图配置详解的相关文章

使用LVS实现负载均衡原理及安装配置详解

转:http://www.cnblogs.com/liwei0526vip/p/6370103.html 使用LVS实现负载均衡原理及安装配置详解 负载均衡集群是 load balance 集群的简写,翻译成中文就是负载均衡集群.常用的负载均衡开源软件有nginx.lvs.haproxy,商业的硬件负载均衡设备F5.Netscale.这里主要是学习 LVS 并对其进行了详细的总结记录. 一.负载均衡LVS基本介绍 LB集群的架构和原理很简单,就是当用户的请求过来时,会直接分发到Director

LVS配置详解

一.LVS系统组成 前端:负载均衡层 –      由一台或多台负载调度器构成 中间:服务器群组层 –      由一组实际运行应用服务的服务器组成 底端:数据共享存储层 –      提供共享存储空间的存储区域 二.LVS术语 Director Server:调度服务器,将负载分发到RealServer的服务器 Real Server:真实服务器,真正提供应用服务的服务器 VIP:虚拟IP地址,公布给用户访问的IP地址 RIP:真实IP地址,集群节点上使用的IP地址 DIP:Director连

logback logback.xml 常用配置详解

一:根节点 包含的属性: scan: 当此属性设置为true时,配置文件如果发生改变,将会被重新加载,默认值为true. scanPeriod: 设置监测配置文件是否有修改的时间间隔,如果没有给出时间单位,默认单位是毫秒.当scan为true时,此属性生效.默认的时间间隔为1分钟. debug: 当此属性设置为true时,将打印出logback内部日志信息,实时查看logback运行状态.默认值为false. 例如: <configuration scan="true" scan

php-fpm的配置详解

php5.3自带php-fpm /usr/local/php/etc/php-fpm.confpid = run/php-fpm.pidpid设置,默认在安装目录中的/var/run/php-fpm.pid,建议开启 error_log = log/php-fpm.log错误日志,默认在安装目录中的/var/log/php-fpm.log log_level = notice错误级别. 可用级别为: alert(必须立即处理), error(错误情况), warning(警告情况), notic

varnish安装及配置详解

varnish系统架构: varnish主要运行两个进程:Management进程和Child进程(也叫Cache进程). Management进程主要实现应用新的配置.编译VCL.监控varnish.初始化varnish以及提供一个命令行接口等.Management进程会每隔几秒钟探测一下Child进程以判断其是否正常运行,如果在指定的时长内未得到Child进程的回应,Management将会重启此Child进程. Child进程包含多种类型的线程,常见的如:Acceptor线程:接收新的连接

Windows下Nginx Virtual Host多站点配置详解

Windows下Nginx Virtual Host多站点配置详解 此教程适用于Windows系统已经配置好Nginx+Php+Mysql环境的同学. 如果您还未搭建WNMP环境,请查看 windows7配置Nginx+php+mysql教程. 先说明一下配置多站点的目的:在生产环境中,如果将系统所有代码文件都放在公开目录中,则很容易被查看到系统源码,这样是很不安全的,所以需要只公开index.php的入口文件目录.而同一个服务器中,可能运行多个系统,这样就必须公开多个入口文件目录,以便用不同的

linux FTP配置详解

一.vsftpd说明: LINUX下实现FTP服务的软件很多,最常见的有vsftpd,Wu-ftpd和Proftp等.Red Hat Enterprise Linux中默认安装的是vsftpd. 访问FTP服务器时需要经过验证,只有经过了FTP服务器的相关验证,用户才能访问和传输文件.vsftpd提供了3种ftp登录形式:  (1)anonymous(匿名帐号) 使用anonymous是应用广泛的一种FTP服务器.如果用户在FTP服务器上没有帐号,那么用户可以以anonymous为用户名,以自己

Log4J日志配置详解

一.Log4j简介 Log4j有三个主要的组件:Loggers(记录器),Appenders (输出源)和Layouts(布局).这里可简单理解为日志类别,日志要输出的地方和日志以何种形式输出.综合使用这三个组件可以轻松地记录信息的类型和级别,并可以在运行时控制日志输出的样式和位置. 1.Loggers Loggers组件在此系统中被分为五个级别:DEBUG.INFO.WARN.ERROR和FATAL.这五个级别是有顺序的,DEBUG < INFO < WARN < ERROR <

keepalived的配置详解(非常详细)

keepalived的配置详解(非常详细) 2017-01-22 15:24 2997人阅读 评论(0) 收藏 举报  分类: 运维学习(25)  转载自:http://blog.csdn.net/u010391029/article/details/48311699 1. 前言 VRRP(Virtual Router Redundancy Protocol)协议是用于实现路由器冗余的协议,最新协议在RFC3768中定义,原来的定义RFC2338被废除,新协议相对还简化了一些功能. 2. 协议说