1

這是我的圖表目前的樣子: enter image description hereHighcharts Y軸標籤

我怎樣才能改變在Y軸上的值等於您可以在工具提示中看到的名稱,即「其他問題」,我想這個名字是在地方目前價格正在攀升的在Y軸的數值

這是我的代碼:

function BarChartCategory() { 

     var arr = @Html.Raw(Json.Encode(@ViewBag.Categories)); 

     console.log(arr); 

     var RNames = [], RValues = [], prev; 

     //Count how many occurances of each value 
     arr.sort(); 
     for (var i = 0; i < arr.length; i++) { 
      if (arr[i] !== prev) { 
       RNames.push(arr[i]); 
       RValues.push(1); 
      } else { 
       RValues[RValues.length-1]++; 
      } 
      prev = arr[i]; 
     } 

     console.log(RValues); 
     console.log(RNames); 

     var final = []; 

     for(var i=0; i < RNames.length; i++) { 
      final.push({ 
       name: RNames[i], 
       y: RValues[i] 
      }); 
     } 

     console.log(final); 


     $('#container').highcharts({ 
      chart: { 
       type: 'bar' 
      }, 
      title: { 
       text: 'By Category Results' 
      }, 
      yAxis: { 
       allowDecimals: false, 

      }, 
      tooltip: { 
       formatter: function() { 
        return '<b>' + this.series.name + '</b><br/>' + 
         this.point.y + ' ' + this.point.name.toLowerCase(); 
       } 
      }, 
      series: [{ 
       name: "Issues: ", 
       colorByPoint: true, 
       data: final 
      }] 
     }); 
    } 

回答

4

我能找到一個解決我的問題,我首先將Yaxis改爲xaxis,並添加了一個我們的循環nt通過陣列中的每個結果

xAxis: { 
       allowDecimals: false, 

       categories: function(){ 
        var data 
        for(var i=0;i< final.length;i++){ 
         data.push({ 
          categories: final[i].name 
         }) 
        }; 
        return data; 
       } 

      } 
+2

是的,對於條形圖,x和y軸是相反的。這與建立柱形圖相同,並設置*倒轉:真正的* – jlbriggs

+0

是的,我花了一段時間才弄清楚這一點,非常混亂。 –