柱形图

作者: 兰夏天 | 来源:发表于2019-05-14 10:58 被阅读0次

如图:


bar.png

html

     <div id="gatechart1" style="width:90%;height:200px;">
<script>
 setechart(id, xdata, gateStresslist, ntype) { // 柱形图
        var myChart = echarts.init(document.getElementById(id));
        var option = {
          tooltip: {
            trigger: 'axis',
            axisPointer: { // 坐标轴指示器,坐标轴触发有效
              type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
            }
          },
          // legend: {
          //   data: ['安全', '超负', '破坏']
          // },
          grid: {
            left: '10%',
            right: '12%',
            top: '10%',
            bottom: '20%',
            containLabel: false
          },
          xAxis: [{
            type: 'category',
            axisTick: {
              show: false
            },
            axisLine: {
              lineStyle: { //坐标轴颜色
                color: '#018baf',
              }
            },
            axisLabel: { //坐标轴字体倾斜
              interval: 0, //但是为了掩饰需要注释掉倾斜,当真正的为时间的时候需要倾斜
              // rotate: 25 //但是为了掩饰需要注释掉倾斜,当真正的为时间的时候需要倾斜
            },
            data: xdata
            // (function () {
            //   var now = new Date();
            //   var res = [];
            //   var len = 12;
            //   while (len--) {
            //     res.unshift(now.toLocaleTimeString().replace(/^\D*/, ''));
            //     now = new Date(now - 2000);
            //   }
            //   return res;
            // })()
            // data : ['周一','周二','周三','周四','周五','周六','周日']
          }],
          yAxis: [{
              //  name:'百分比',
              type: 'value',
              splitLine: {
                show: false, //控制网格线是否显示
                lineStyle: {
                  color: ['#018baf'] //控制网格线颜色
                }
              },
              axisLine: {
                lineStyle: { //控制坐标轴颜色
                  color: '#018baf',
                }
              },
              min: -0.50,
              max: 0.50,
              interval: 0.15,
            }

          ],
          series: [{
            name: '安全',
            // type: 'bar',
            type: ntype,
            barWidth: 10,
            itemStyle: {
              normal: {
                //   color: '#00ffea', // 柱状图的颜色
                color: function (params) { //根据数值大小显示柱状图的颜色,同一类
                  var index_color = params.value;

                  if (Math.abs(index_color) >= 0 && Math.abs(index_color) < 0.25) {
                    return '#00ffea';
                  } else if (Math.abs(index_color) >= 0.25 && Math.abs(index_color) < 0.4) {
                    return '#f3ff68';
                  } else if (Math.abs(index_color) >= 0.4 && Math.abs(index_color) < 0.5) {
                    return '#bf5aff';
                  }
                },

                // color: function () {
                //   // for(var ite of gateStresslist){
                //   //   if(ite>0.3){
                //   //     return 'red'
                //   //   }else{
                //   //     return '#00ffea'
                //   //   }
                //   // }
                //   // gateStresslist
                //   //  return 'red'
                //   return '#00ffea'
                // }
              }
            },

            label: {
              normal: {
                show: true,
                position: 'inside',
                color: 'red'
              }
            },
            // data:[0.200, 0.170, 0.240, 0.244, 0.200, 0.220, 0.210]
            data: gateStresslist
          }, ]
        };

        //======== start 这个是实时函数,根据当前时间一直改变横为当前时间轴时间点段范围,及柱形图的数据也会随机变化,但是为展示需要注释掉让其显示静态
        setInterval(function () {
          var axisData = (new Date()).toLocaleTimeString().replace(/^\D*/, '');
          var data0 = option.series[0].data;
          data0.shift();
          //  var that = this
          data0.push((Math.random() - 0.5).toFixed(2));
          //        that.sernum++
          //         if (that.sernum) {
          //            that.sernum=!that.sernum
          // data0.push((Math.random() * 0.5).toFixed(2));
          //         //  data0.push((parseFloat( (Math.random() * 0.5).toFixed(2))).toString());
          //         } else  {
          //           that.sernum=!that.sernum
          //       data0.push(-(Math.random() * 0.5).toFixed(2));

          //data0.push((-parseFloat( (Math.random() * 0.5).toFixed(2))).toString());
          //}
          // option.xAxis[0].data.shift(); //这个就是实时改变当前时间每添加一个新时间前除去一个旧时间
          // option.xAxis[0].data.push(axisData);// 这个就是实时改变当前时间
          myChart.setOption(option);
        }, 2100);
        //======== end 这个是实时函数,根据当前时间一直改变横为当前时间轴时间点段范围,及柱形图的数据也会随机变化,但是为展示需要注释掉让其显示静态
        myChart.setOption(option);
      }

 //this.setechart('gatechart1', this.xdata(12), this.gateStress(12), 'bar') // 实时 动态的,根据当前时间
      // setechart('gatechart2', this.xdata(9), this.gateStress(9), 'bar') // 实时 动态的,根据当前时间

      var xdataone = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
        datatwo = [1, 2, 3, 4, 5, 6, 7, 8, 9],
        gateStressone = [0.20, 0.37, 0.24, -0.24, 0.20, -0.22, 0.21, -0.48, 0.11, -0.18, 0.17, 0.24],
        gateStresstwo = [-0.24, 0.20, -0.22, 0.21, -0.38, 0.11, -0.18, 0.17, 0.44];
      setechart('gatechart1', xdataone, this.gateStress(12), 'bar') // 实时 动态的,根据当前时间
      setechart('gatechart2', datatwo, this.gateStress(9), 'bar') // 实时 动态的,根据当前时间

      // setechart('gatechart1', xdataone, gateStressone, 'bar') // 静态的 为展示效果
      // setechart('gatechart2', datatwo, gateStresstwo, 'bar') // // 静态的 为展示效果
</script>

相关文章

  • python matplotlib(pymatplotlib)

    堆叠柱形图 并列柱形图 水平柱形图 破损柱形图 分类变量图 堆叠柱形图 并列柱形图 水平柱形图 破损柱形图 分类变量图

  • echarts

    项目安装 线形图 柱形图 横向柱形图 饼图

  • 数据分析图表类之花式运用“柱状图”

    柱形图是我们最常用的一类图表,常用来分析每类数据“有多少”的问题。柱形图又可以延伸为簇状柱形图、堆积柱形图、百分比...

  • Python强大的pyecharts绘画优美图形<二>

    常用图形:柱形图-折线图-饼图-散点图 柱形图 对应的图像如下 折线图 对应图形如下 柱形图-折线图 饼图 散点图...

  • 柱形图在PPT里的美化

    哈喽,大家好,我是诗珑。 今天给大家分享的是图表——柱形图在PPT中的美化。 柱形图主要包括:簇状柱形图、堆积柱形...

  • 5分钟教你用python制作带精美图形的PPT

    本 5分钟系列将会讲解如何在python中如何自动在PPT里画柱形图,并将其扩展为多柱形图。最后给每个柱形图标上对...

  • R语言绘图合集

    一、类别比较型图 [R-柱形图系列] R-柱形图[http://mp.weixin.qq.com/s?__biz=...

  • ggplot2应用(一)——柱形图

    前言 柱形图属于类别比较型图表,包括单数据系列柱状图、多数据系列柱状图、堆积柱状图和百分比堆积柱形图。柱形图一般适...

  • WPS表格:火箭柱形图

    火箭柱图 本篇适合:已适配小白。 QQ交流群:644328490。 需求:生成图-1的火箭柱形图: 关键词:柱形图...

  • 使用Python绘制柱形图

    使用pyplot的 bar()函数可以快速绘制柱形图或堆积柱形图。bar()函数的语法格式如下所示: 该函数常用参...

网友评论

      本文标题:柱形图

      本文链接:https://www.haomeiwen.com/subject/yngjaqtx.html