javascript Highcharts X 轴标签作为文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19381530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Highcharts X-Axis labels as Text
提问by Srinivas
In this fiddle, with out changing the series data, Is it possible to show x-axis labels as text i.e. {"apple","orange","mango"}
instead of decimals i.e {0,1,2}
with out separating labels from JSON and providing it to Categories.
在这个小提琴中,不更改系列数据,是否可以将 x 轴标签显示为文本,即{"apple","orange","mango"}
代替小数,即{0,1,2}
不将标签与 JSON 分开并将其提供给类别。
$(function () {
$('#container').highcharts({
chart: {
},
xAxis: {
labels: {
enabled: true
}
},
series: [{
data: [["apple",29.9], ["orange",71.5], ["mango",106.4]]
}]
});
});
回答by Nitish Kumar
Try this:
试试这个:
$(function () {
var seriesData = [["apple",29.9], ["orange",71.5], ["mango",106.4]];
$('#container').highcharts({
chart: {
},
xAxis: {
tickInterval: 1,
labels: {
enabled: true,
formatter: function() { return seriesData[this.value][0];},
}
},
series: [{
data: seriesData
}]
});
});
SEE DEMO
看演示
回答by Strikers
You can use catgories
in xAxis
您可以catgories
在xAxis
xAxis: {
categories: ["apple", "orange", "mango"],
}
I've updated your fiddle: http://jsfiddle.net/Lq6me/1/
我已经更新了你的小提琴:http: //jsfiddle.net/Lq6me/1/
If you don't want to use categories you can go for
如果你不想使用类别,你可以去
labels: {
formatter: function() {}
}
回答by Vikram
No need to do it manually the better solution is just pass type: 'category'in xAxis block. Look below snippet
无需手动执行,更好的解决方案是在 xAxis 块中传递type: 'category'。看下面的片段
xAxis: {
type: 'category',
labels: {
rotation: -45,
style: {
fontSize: '13px',
fontFamily: 'Verdana, sans-serif'
},
}
}