利用echart 作以特定數值爲分界線的圖表

利用echart 作以特定數值爲分界線的圖表,下面的例子以1爲分界線的例子
     <script>
   var axisData = ["8","9","10","11","12","13","14","15","16","17","18"];
     var yxisData = [0.26, 1.01, 1.17, 1.17, 0.77, 0.90, 3.03, 0.99, 1.19, 4.83, 1.57];
     var yxisData0=[];
     var yxisData1=[];
     var interval;
     var maxy = Math.max.apply(null,yxisData);
     if(maxy <= 2){
       interval=0.1;
     }else{
       interval=0.2;
     }
  $.each(yxisData,function(index,item){
  if(item >=1)
  {
   item -=1;
   yxisData1.push(item);
   yxisData0.push(1);
  }
  else
  {
   yxisData1.push(1-item);
   yxisData0.push(item);
  }
  }) 
option1 = {
      title : { 
                text : '公司名稱', 
            },
     legend: { 
                data:['不均勻係數'],
                },
     tooltip : {
        trigger: 'axis',
        axisPointer : {            // 座標軸指示器,座標軸觸發有效
            type : 'shadow'        // 默認爲直線,可選爲:'line' | 'shadow'
        },
        formatter: function (params) {
            var tar;
            tar = params[1];
            return tar.name + '<br/>' + tar.seriesName + ' : ' + (yxisData[tar.dataIndex]);
        }
    },
 grid: {},
    xAxis : [
        {
            type : 'category',
            data : axisData
        }
    ],
   yAxis: {interval:interval, },// y軸不能刪除
     series: [
        {
            name: '輔助',
            type: 'bar',
            stack: '總量',
            itemStyle: {
                normal: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                },
                emphasis: {
                    barBorderColor: 'rgba(0,0,0,0)',
                    color: 'rgba(0,0,0,0)'
                }
            },
   data:yxisData0
        },
        {
            name: '不均勻係數',
            type: 'bar',
            stack: '總量',
            data: yxisData1
        },
  ]
};
   var myChart1 = echarts.init(document.getElementById('barchart1'),theme);
  myChart1.setOption(option1);
  ObjectResize(myChart1.resize)
  function ObjectResize(fn){
  if(window.addEventListener)
 {
 window.addEventListener("resize",fn,false);
   }
  else
  {
 window.attachEvent("onresize",fn)
  }
  }
 </script>app

相關文章
相關標籤/搜索