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

是的,我花了一段时间才弄清楚这一点,非常混乱。 –