Javascript 如何使用highcharts呈现整体数据标签?
在下图中显示数据标签的Javascript 如何使用highcharts呈现整体数据标签?,javascript,jquery,charts,highcharts,Javascript,Jquery,Charts,Highcharts,在下图中显示数据标签的targets变量时遇到问题。 由于某些原因,序列数据标签仅显示targetsAdj值。 我尝试在y轴上添加堆叠标签,但没有成功。否则怎么做呢 ar targets = [<?php echo $gg[0][24].",".$gg[0][20].",".$gg[0][26].",".$gg[0][22].""; ?>], mcbf = [ <?php echo $gg[0][16].",".$gg[0][17].",".$gg[0][18].",".$
targets
变量时遇到问题。
由于某些原因,序列数据标签仅显示targetsAdj
值。
我尝试在y轴上添加堆叠标签,但没有成功。否则怎么做呢
ar targets = [<?php echo $gg[0][24].",".$gg[0][20].",".$gg[0][26].",".$gg[0][22].""; ?>],
mcbf = [ <?php echo $gg[0][16].",".$gg[0][17].",".$gg[0][18].",".$gg[0][19].""; ?>],
targetsAdj = [],
attagg=[],
calc,
calc2;
for (var i=0;i<targets.length;i++) {
calc = targets[i] >= mcbf[i] ? targets[i] - mcbf[i] : 0;
targetsAdj.push(calc);
}
for (var i=0;i<mcbf.length;i++) {
calc2 = (mcbf[i]/targets[i])>=0.7 ? {y:mcbf[i],color:'#1de9b6',borderColor:'#00bfa5'} : ((mcbf[i]/targets[i])>=0.4 ? {y:mcbf[i],color:'#ffeb3b',borderColor:'#fdd835'}:{y:mcbf[i],color:'tomato',borderColor:'#d84315'});
attagg.push(calc2);
}
$('#attivazioni').highcharts(
{
"colors":
["tomato"
, "lime"
, "rgba(139,188,33,.5)"
, "rgba(145,0,0,.5)"
, "rgba(26,173,206,.5)"
, "rgba(73,41,112,.5)"
, "rgba(242,143,67,.5)"
, "rgba(119,161,229,.5)"
, "rgba(196,37,37,.5)"
, "rgba(166,201,106,.5)"],
"chart": {
"zoomType": "x",
"showAxis": true,
"alignTicks": true,
//"height": 300,
"style": {
"fontFamily": "Helvetica, Arial, sans-serif",
"color": "#333"
},
"backgroundColor": "#ffffff"
},
"title": {
"text": " "
},
"xAxis": [{
"tickmarkPlacement": "on",
"labels": {
"style": {
"fontSize": "10px",
"color": "#333"
},
"useHTML": true
},
"gridLineColor": "lightgrey",
"gridLineWidth": 0,
"categories": ["<span style=\"font-size:12px\"><b>Lead</span>"
, "<span style=\"font-size:12px\"><b>Lvc</span>"
, "<span style=\"font-size:12px\"><b>Push</span>"
, "<span style=\"font-size:12px\"><b>AddOn</span>"]
}],
"yAxis": [{
"alternateGridColo": "null",
"minorTickInterval": "auto",
"lineColor": '#000',
"tickWidth": "1",
"tickColor": '#000',
"gridLineColor": "#C0C0C0",
"gridLineWidth": 1,
"lineColor": "#C0C0C0",
"lineWidth": 1,
"endOnTick": true,
"min": 0,
"labels": {
"formatter": function () {
return '%' + this.axis.defaultLabelFormatter.call(this);
} ,
"style": {
"fontSize": "10px",
"color": "black"
}
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: (Highcharts.theme && Highcharts.theme.textColor) || 'gray'
},
formatter: function() {
return Highcharts.numberFormat(this.total, 2, ',');
}
},
title: {
text: '',
style: {
display: 'none'
}
},
subtitle: {
text: '',
style: {
display: 'none'
}
},
}],
"legend": {
"enabled": false
},
"navigation": {
"buttonOptions": {
"enabled": false
}
},
"plotOptions": {
"series": {
"dataLabels": {
"enabled": true,
"style": {
"color": "#333"
},
"crop": false,
"overflow": "none"
},
"shadow": false,
"marker": {
"enabled": false
}
},
"column": {
"grouping": false,
"stacking": "percent",
"shadow": false
}
},
"credits": {
"enabled": false
},
"tooltip": {
"enabled": false,
"shared": true,
"valueDecimals": 0
},
"series": [{
"name": "Target",
"type": "column",
"color": "rgba(140, 131, 131, 0.49)",
"borderColor": "#B0BEC5",
"borderWidth": 2,
"data": targetsAdj,
"dataLabels": {
y:-18,
verticalAlign:'top',
"formatter": function() {
if (this.series.index == 0) return targets[this.point.x];
else return this.y;
}
}
},{
"name": "SELLS",
"type": "column",
"data": attagg,
"color": "#1de9b6",
"borderColor": "grey",
"borderWidth": 2,
"zIndex": 10
} ]
});
ar目标=[],
mcbf=[],
targetsAdj=[],
attagg=[],
计算,
calc2;
对于(var i=0;i=mcbf[i]?目标[i]-mcbf[i]:0;
目标推力(计算);
}
对于(变量i=0;i=0.7?{y:mcbf[i],颜色:'#1de9b6',边框颜色:'#00bfa5'}:((mcbf[i]/targets[i])>=0.4?{y:mcbf[i],颜色:'#ffeb3b',边框颜色:'#fdd835'}:{y:mcbf[i',颜色:'tomato',边框颜色:''d84315});
附加推力(calc2);
}
$('attivazioni')。高图(
{
“颜色”:
[“西红柿”
“石灰”
,“rgba(139188,33,5)”
,“rgba(145,0,0,5)”
,“rgba(26173206,.5)”
,“rgba(73,41112,5)”
,“rgba(242143,67,5)”
,rgba(119161229.5)
,“rgba(196,37,37,5)”
,“rgba(166201106.5)”,
“图表”:{
“zoomType”:“x”,
“showAxis”:正确,
“alignTicks”:对,
//“高度”:300,
“风格”:{
“fontFamily”:“Helvetica,Arial,无衬线”,
“颜色”:“333”
},
“背景色”:“#ffffff”
},
“标题”:{
“文本”:”
},
“xAxis”:[{
“滴答声”:“开”,
“标签”:{
“风格”:{
“fontSize”:“10px”,
“颜色”:“333”
},
“useHTML”:true
},
“gridLineColor”:“浅灰色”,
“网格线宽”:0,
“类别”:[“潜在客户”
,“Lvc”
“推”
,“附加组件”]
}],
“yAxis”:[{
“alternateGridColo”:“null”,
“minorTickInterval”:“自动”,
“lineColor”:“#000”,
“滴答声宽度”:“1”,
“tickColor”:“#000”,
“gridLineColor”:“#C0C0”,
“网格线宽度”:1,
“线条颜色”:“#C0”,
“线宽”:1,
“endOnTick”:没错,
“min”:0,
“标签”:{
“格式化程序”:函数(){
返回“%”+this.axis.defaultLabelFormatter.call(this);
} ,
“风格”:{
“fontSize”:“10px”,
“颜色”:“黑色”
}
},
堆叠标签:{
启用:对,
风格:{
fontWeight:'粗体',
颜色:(Highcharts.theme&&Highcharts.theme.textColor)| |“灰色”
},
格式化程序:函数(){
返回Highcharts.numberFormat(this.total,2',');
}
},
标题:{
文本:“”,
风格:{
显示:“无”
}
},
副标题:{
文本:“”,
风格:{
显示:“无”
}
},
}],
“传奇”:{
“已启用”:false
},
“导航”:{
“按钮选项”:{
“已启用”:false
}
},
“打印选项”:{
“系列”:{
“数据标签”:{
“启用”:正确,
“风格”:{
“颜色”:“333”
},
“作物”:假,
“溢出”:“无”
},
“影子”:假,
“标记”:{
“已启用”:false
}
},
“列”:{
“分组”:错误,
“堆叠”:“百分比”,
“影子”:假
}
},
“学分”:{
“已启用”:false
},
“工具提示”:{
“启用”:false,
“共享”:是的,
“valueDecimals”:0
},
“系列”:[{
“名称”:“目标”,
“类型”:“列”,
“颜色”:“rgba(1401311310.49)”,
“边框颜色”:“#B0BEC5”,
“边界宽度”:2,
“数据”:targetsAdj,
“数据标签”:{
y:-18,
垂直线:'顶部',
“格式化程序”:函数(){
if(this.series.index==0)返回目标[this.point.x];
否则返回这个.y;
}
}
},{
“名称”:“销售”,
“类型”:“列”,
“数据”:附件,
“颜色”:“#1de9b6”,
“边框颜色”:“灰色”,
“边界宽度”:2,
“zIndex”:10
} ]
});
我通过将series datalabels设置为false,并将yaxis设置更改为:
yAxis: {
min: 0,
max: 105,
endOnTick: false,
title: {
text: null
},
stackLabels: {
enabled: true,
style: {
fontWeight: 'bold',
color: 'black'
}
}
},