【发布时间】:2019-05-22 11:20:05
【问题描述】:
我正在尝试为 HighChart 中的条形图设置自定义 x 轴标签。我使用格式化程序将 % 和 里程碑日期 添加到标签中。当我在控制台中打印时,我可以看到预期的结果,但条形图标签没有反映这个值。
请在附件中找到我尝试过的小提琴。
https://jsfiddle.net/mt74opnu/2/
Code:
/* public milestonedata: MilestoneDetailsSchedule = {
tickInterval: 30,
milestonedetails: [{
percentage: 30,
milestonedate: "May 1, 2019"
}, {
percentage: 60,
milestonedate: "May 25, 2019"
}]
}; // this the object that I am trying to access for labels */
Highcharts.chart('container', {
chart: {
type: 'bar'
},
xAxis: {
categories: ['My Goal', 'My Progress', 'My Branch', 'My Region']
},
yAxis: {
min: 0,
max: 100,
tickInterval: 30,
labels: {
overflow: 'justify',
formatter: function() {
//console.log('In charts');
//console.log(this.value);
var milestonedata = {
tickInterval: 30,
milestonedetails: [{
percentage: 30,
milestonedate: "May 1, 2019"
}, {
percentage: 60,
milestonedate: "May 25, 2019"
}]
};
var result;
milestonedata.milestonedetails.forEach((milestone) => {
//console.log(milestone);
//would like the labels to be 30% by date1, 60% by date 2
if (milestone.percentage == this.value && milestone.milestonedate) {
result = this.value + "% by <br>" + milestone.milestonedate;
console.log(result);
} else {
result = this.value;
}
return result;
});
}
}
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
series: [{
data: [{
y: 25
}, {
y: 50
}, {
y: 75
}, {
y: 100
}]
}]
});
我想查看 x 轴标签:该值的 值 + % + 里程碑日期。 例如:到 2019 年 5 月 1 日达到 30% 等
这可能吗?提前致谢!
【问题讨论】:
标签: angular typescript highcharts