2013-05-08 95 views
1

我正在改变我的x轴值的标签。尝试完成后,没有任何x轴标签的显示。Highcharts:我正在更换x轴标签,为什么标签没有显示?

JavaScript代码

$(document).ready(function() { 
var labels = [ '5/7','5/7','5/7','5/7','5/7','5/7','5/7','5/7','5/7','5/7' ]; 
chart = new Highcharts.Chart({ 
    chart: { renderTo:'chart_container' }, 
    title: { text: 'Rev Load' }, 
    xAxis: { categories: ['5/7 64298-R3', '5/7 64308-R3', '5/7 64311-R3', '5/7 64312-R3', '5/7 64302-R3', '5/7 64307-R3', '5/7 64309-R3', '5/7 64297-R3', '5/7 64310-R3', '5/7 64305-R3'], labels: { 
      formatter: function() { return labels[this.value];} }, 
      tickInterval: 3 }, 
    yAxis: { max: 0.0018, min: 0.0014, plotLines: [{ color: 'red', dashStyle: 'shortDash', value: 0.0018, width: 2 }, { color: 'red', dashStyle: 'shortDash', value: 0.0014, width: 2 }], title: { text: '' } }, 
    series: [{ data: [0.00150, 0.00170, 0.00140, 0.00180, 0.00150, 0.00160, 0.00140, 0.00150, 0.00180, 0.00160], name: 'Values' }] 
}); 

C#代码DOTNET的

chart.SetXAxis(new XAxis 
     { 
      Categories = categories.ToArray(), 
      TickInterval = 3, 
      Labels = new XAxisLabels { Formatter = "function() { labels[this.value];} " } 

     }); 

什么当前显示 enter image description here

由于截图SH截图允许点的x轴标签丢失。

P.S.我不是指x轴标题,而是x-axis labels

背景信息

请让我知道是否有该问题的任何误解。感谢您的帮助和帮助!

编辑 - 我固定的问题与缺失return关键字,但它看起来像它仍然没有显示标签

回答

2

从您的标签格式化功能你不返回一个值 - 尝试

formatter: function() { return labels[this.value];} } 

另一个问题是,this.value格式化功能里面是一样的东西“5/7 64298-R3”,所以labels[this.value]是不确定的。

它看起来像你想显示的数值的第一部分 - 如果是这样,请尝试:

formatter: function() { return this.value.split(" ")[0]; } 
+0

哇哦......这样一个愚蠢的错误。 haha – AustinT 2013-05-09 15:03:32

+0

我修正了这个错误,因为我更新了我的文章。但看起来标签仍然没有显示。 – AustinT 2013-05-09 15:06:17

+0

更新了我的答案 - 传递给格式化程序函数的值不是索引。 – mike 2013-05-10 04:25:13