jquery highcharts y 轴上的文本
您好,我正在尝试创建一个带有高图表的简单柱形图。
该图表显示了学生四项作业的成绩。
四个分配中的每一个都在 x 轴上列出。
y 轴应连续显示每个可能的等级 A - E(即每个字母必须出现在轴上,即使系列中没有该等级的数据)。
我尝试使用数字来表示系列数据中的成绩,然后使用 Highcharts 中的建议y 轴的文本标签 手动填充 y 轴,但仅显示第一年级。
另外,当我在标签格式化程序函数中 alert(this.value)
时,我得到了一系列返回的零星数字(0,500,0,5,10),其中只有几个与我的系列数据中的数字。请帮忙!
这是我的代码;
$(document).ready(function(){
var seriesData = [{
name: 'Grade',
data: [5,2,1,4]
}];
var xAxisLabels = {categories: ['Assignment One', 'Assignment Two', 'Assignment Three', 'Assignment Four']};
var yAxisLabels = ['E','D','C','B','A'];
var chart = new Highcharts.Chart({
chart: {
renderTo: 'chart',
defaultSeriesType: 'column'
},
series: seriesData,
xAxis: xAxisLabels,
yAxis: {
labels: {
formatter: function() {
return yAxisLabels[this.value];
}
}
}
});
});
Hi I am trying to create a simple column chart with high charts.
The chart displays a students grades for four assignments.
Each of the four assignments is listed across the x-axis.
The y Axis should display each of the possible grades A - E consecutively (i.e. each letter MUST appear on the axis, even if there is no data in the series for that grade).
I have tried using numbers to signify the grades in my series data and then using the suggestion at Highcharts text labels for y-axis to manually populate the y-axis, but only the first grade shows.
Plus, when I alert(this.value)
in the label formatter function, I get a sporadic series of numbers returned(0,500,0,5,10), of which only a couple bare any relation to the numbers in my series data. Help Please!
Here is my code;
$(document).ready(function(){
var seriesData = [{
name: 'Grade',
data: [5,2,1,4]
}];
var xAxisLabels = {categories: ['Assignment One', 'Assignment Two', 'Assignment Three', 'Assignment Four']};
var yAxisLabels = ['E','D','C','B','A'];
var chart = new Highcharts.Chart({
chart: {
renderTo: 'chart',
defaultSeriesType: 'column'
},
series: seriesData,
xAxis: xAxisLabels,
yAxis: {
labels: {
formatter: function() {
return yAxisLabels[this.value];
}
}
}
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 javascript 数组索引从 0 开始,因此您必须添加一个空标签,因为您的值范围从 (5:A 到 1:E)。
我添加了一个工具提示格式化程序来更改工具提示的标签以显示成绩而不是数值。
Since javascript array indices start at 0 you have to add an empty label since your values range from (5:A to 1:E).
I added a tooltip formatter to change the label of the tooltip to show the grades as well and not the numeric values.