javascript – 根据highcharts中的Column值更改Datalabel Color,Rotation和Align值
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了javascript – 根据highcharts中的Column值更改Datalabel Color,Rotation和Align值,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2173字,纯文字阅读大概需要4分钟。
内容图文
未解决的highcharts datalabel dynamic rotation as column height可能重复
样本柱形图的小提琴:http://jsfiddle.net/Yrygy/266/
有一些非常大的列和一个非常小的列.我想在大列中显示垂直旋转到-90度的白色标签,对于较小的列,我想在列顶部显示深灰色标签,旋转0度.
经过一番搞砸后,我实现了这个目标:http://jsfiddle.net/Yrygy/267/
我可以根据格式化程序函数中的值更改标签的颜色,但使用全局变量来获得对齐和向右旋转不起作用.
在这方面的任何帮助都会非常有帮助.我不能使用重复问题中建议的解决方案,因为我需要保持Y轴均匀并且不能设置MinPointLength.
最终守则:
var GlobalRotation = -90;
var GlobalAlign = 'right';
var X;
var Y;
$(function () {
$('#container').highcharts({
chart: {
type: 'column',
height: 700
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
plotOptions: {
column: {
stacking: 'normal',
pointPadding: 0,
groupPadding: 0.2,
dataLabels: {
enabled: true,
inside: false,
style: {
fontWeight: 'bold'
},
formatter: function() {
var max = this.series.yAxis.max,
color = this.y / max < 0.05 ? 'black' : 'white';
//GlobalRotation = this.y / max < 0.05 ? 0 : -90;
//GlobalAlign = this.y / max < 0.05 ? 'left' : 'right';
//X = this.y / max < 0.05 ? 4 : 4;
//Y = this.y / max < 0.05 ? 0 : 5;
return '<span style="color: ' + color + '">' + this.y + ' </span>';
},
verticalAlign: "top",
rotation : GlobalRotation,
align: GlobalAlign
}
}
},
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 2.33]
}]
});
});
解决方法:
您可以更改Highcharts.Series.prototype.drawDataLabels,绘制dataLabels的函数:
Highcharts.Series.prototype.drawDataLabels = (function (func) {
return function () {
func.apply(this, arguments);
if (this.options.dataLabels.enabled || this._hasPointLabels) realignLabels(this);
};
}(Highcharts.Series.prototype.drawDataLabels));
realignLabels将是检查较短列的函数,并在其中更改特定dataLabel的旋转,x和y:
function realignLabels(serie) {
$.each(serie.points, function (j, point) {
if (!point.dataLabel) return true;
var max = serie.yAxis.max,
labely = point.dataLabel.attr('y'),
labelx = point.dataLabel.attr('x');
if (point.y / max < 0.05) {
point.dataLabel.attr({
y: labely - 20,
x: labelx + 5,
rotation: 0
});
}
});
};
http://jsfiddle.net/Yrygy/270/
内容总结
以上是互联网集市为您收集整理的javascript – 根据highcharts中的Column值更改Datalabel Color,Rotation和Align值全部内容,希望文章能够帮你解决javascript – 根据highcharts中的Column值更改Datalabel Color,Rotation和Align值所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。