echarts柱狀圖每個柱子顯示不同顏色,並且能夠實現點擊每種顏色影藏對應柱子的功能


---------------------------------------------------------代碼區---------------------------------------------------------------

<!DOCTYPE html>
<html>
  <head>
  <base href="<%=basePath%>">
  <title>測試</title>
  
  <meta http-equiv="pragma" content="no-cache">
  <meta http-equiv="cache-control" content="no-cache">
  <meta http-equiv="expires" content="0">  
  <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  <meta http-equiv="description" content="This is my page">
  <link rel="stylesheet" href="admin/css/bootstrap.min.css">
  
  
</head>

<body>
    <section class="hj-second-page-section">
      <div class="container-fluid">
        <div class="rows">
          <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="rows">
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 hj-jumbotron-div">
                <div class="panel panel-primary ng-scope">
                
                 <!-- pannel start -->
                 <div class="panel-body vc-pannel-body-toggle">
                     <div class="rows ng-scope">
                       <div class="panel-body vc-msg-panel-body">
                         <div class="row">
                          
                          <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6">
                             <div id="rt_chart1" style=""></div>
                          </div>
                          
                         </div>
                      </div>
                     </div>
                     
                 </div>
                
                 <!-- pannel end -->
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
      
    
    <script src="echarts.js"></script>
    <script src="jquery-2.2.3.min.js"></script>
    
    <script>
      /**
       * @description 繪制柱狀圖
       * @author luohan
       * @date 2017-7-28
       * @param
       */
      function initChart1() {
        $("#rt_chart1").height(460);
        $("#rt_chart1").width(1005);
        $("#rt_chart1").css("border","1px solid #ddd");
        var myChart1 = echarts.init(document.getElementById("rt_chart1"));

        var option1 = {
          title : {
            text: '數據統計',
            subtext: ''
          },
          tooltip : {
            trigger: 'axis'
          },
          legend: {
            data:['北京','上海','深圳','廣州']
          },
          toolbox: {
            show : true,
            feature : {
              mark : {show: true},
              dataView : {show: true, readOnly: false},
              magicType : {show: true, type: ['line', 'bar']},
              restore : {show: true},
              saveAsImage : {show: true}
            }
          },
          calculable : true,
          xAxis : [
            {
              type : 'category',
              show:false,
              data : ['橫坐標自定義']
            }
          ],
          yAxis : [
            {
              type : 'value'
              
            }
          ],
          series : [
            {
              name:'北京',
              type:'bar',
              itemStyle: {
                normal: {
                  color: function(params) {
                    //首先定義一個數組
                    var colorList = [
                      '#C33531'
                    ];
                    return colorList[params.dataIndex]
                  },
                  //以下為是否顯示
                  label: {
                    show: false
                  }
                }
              },
              data:[2.0],
            },
            {
              name:'上海',
              type:'bar',
              itemStyle: {
                normal: {
                  color: function(params) {
                    //首先定義一個數組
                    var colorList = [
                      '#EFE42A'
                    ];
                    return colorList[params.dataIndex]
                  },
                  //以下為是否顯示
                  label: {
                    show: false
                  }
                }
              },
              data:[4.9],
            },
            {
              name:'深圳',
              type:'bar',
              itemStyle: {
                normal: {
                  color: function(params) {
                    //首先定義一個數組
                    var colorList = [
                      '#64BD3D'
                    ];
                    return colorList[params.dataIndex]
                  },
                  //以下為是否顯示
                  label: {
                    show: false
                  }
                }
              },
              data:[7.9],
            },
            {
              name:'廣州',
              type:'bar',
              itemStyle: {
                normal: {
                  color: function(params) {
                    //首先定義一個數組
                    var colorList = [
                      '#EE9201'
                    ];
                    return colorList[params.dataIndex]
                  },
                  //以下為是否顯示
                  label: {
                    show: false
                  }
                }
              },
              data:[23.0],
            }
          ]
        };

        


        // 為echarts對象加載數據
        myChart1.setOption(option1);
      }

      initChart1();
    </script>
</body>
</html>
    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM