未显示系列最后一点的Highcharts数据标签
我想在折线图中系列的最后一点上显示数据标签,并添加了以下代码:未显示系列最后一点的Highcharts数据标签,highcharts,Highcharts,我想在折线图中系列的最后一点上显示数据标签,并添加了以下代码: dataLabels: { enabled: true, formatter: function() { if (this.x == this.series.data[this.series.data.length - 1].x) { return 'Test'; } else { return null; } } }, 不幸的是,数
dataLabels: {
enabled: true,
formatter: function() {
if (this.x == this.series.data[this.series.data.length - 1].x) {
return 'Test';
} else {
return null;
}
}
},
不幸的是,数据标签没有显示出来。请参见您可以查看此=>
Highcharts.chart('container'{
图表:{
身高:800,
风格:{
颜色:“#2e4964”,
},
活动:{
加载(){
让图表=这个;
chart.series.forEach(s=>{
s、 设置状态(“非活动”)
})
}
}
},
标题:{
文本:“Corona”,
对齐:“左”,
y:20,
保证金:0,
风格:{
颜色:“#292929”,
重量:'700',
重量:'600',
fontSize:'22px',
fontFamily:“菲拉无衬线,无衬线”
}
},
副标题:{
文字:“潘德米耶之王”,
对齐:“左”,
是的,
风格:{
fontFamily:“罂粟花”,
fontWeight:'400',
颜色:“#3737”,
字体大小:“14px”
}
},
xAxis:[{
类型:'线性',
民:1,,
最高:40,
时间间隔:5,
长度:5,
标签:{
风格:{
fontFamily:“罂粟花”,
fontWeight:'400',
颜色:“#3737”,
字体大小:“14px”
}
},
标题:{
文本:“”
}
}],
亚克斯:[{
类型:'对数',
最高:40000,
//minorTickInterval:1,
最低:100,,
标题:{
文本:空
},
标签:{
风格:{
fontFamily:“罂粟花”,
fontWeight:'400',
颜色:“#3737”,
字体大小:“14px”
}
}
}],
出口:{
按钮:{
上下文按钮:{
已启用:false
}
}
},
图例:{
启用:对,
相反:错,
标题:{
文本:“州和阿伯伦州:”,
风格:{
fontFamily:“罂粟花”,
重量:'600',
颜色:“#3737”,
字体大小:“14px”
}
},
布局:“水平”,
对齐:“左”,
垂直排列:“顶部”,
宽度:300,
最大高度:200,
x:-8,
填充:10,
浮动:假,
边框宽度:0,
影子:错,
项目名称:1,
项目样式:{
fontFamily:“罂粟花”,
fontWeight:'400',
颜色:“#3737”,
字体大小:“14px”
}
},
//工具提示:{
//分享:错,
//是的,
//headerFormat:'Tag{point.x}
',
//点格式:'● {series.name}:{point.y:,.0f}
,
// },
工具提示:{
是的,
启用:对,
外:是的,
格式化程序:函数(){
返回“+”标记“+this.x+”
“+this.series.name+”:“+Highcharts.numberFormat(this.point.y,0)+”;
}
},
学分:{
href:“”,
职位:{
对齐:“右”,
y:-35,
},
正文:“Quellen:JHU CSSE,世卫组织疾病预防控制中心,NHC,丁香玉”,
风格:{
光标:“箭头”,
fontFamily:“罂粟花”,
fontWeight:'正常',
字体大小:“12px”
}
},
打印选项:{
系列:{
数据标签:{
对齐:“右”,
启用:对,
allowOverlap:是的,
格式化程序:函数(){
if(this.x==this.series.data[this.series.data.length-1].x){
返回“”+Highcharts.dateFormat(“%e.%B”,this.x)+':
'+''+Highcharts.numberFormat(this.y,0)+'';
}否则{
返回null;
}
},
风格:{
文本大纲:0,
fontFamily:“罂粟花”,
fontWeight:'400',
颜色:“#000”,
字体大小:“12px”
}
},
标记:{
符号:'圆',
已启用:false
}
}
},
数据:{
googleSpreadsheetKey:'13GJVLHHCZKLNCC1DV3STGEWLBLWX3GXTO3SN9F3GQC',
完成:功能(选项){
options.series[0]。data.forEach(点=>{
如果(点[1]==0){
点[1]=空;
}
});
}
},
系列:[{
颜色:“#8ebfd7”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“rgb(70151190)”,
不透明度:0.5,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#266f9a”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#1c2b54”,
不透明度:1,
数据标签:{
启用:对,
格式化程序:函数(){
if(this.x==this.series.data[this.series.data.length-1].x){
返回“测试”;
}否则{
返回null;
}
}
},
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:'#780081',
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#9c00b3”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#b3007b”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#b30012”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#b36d00”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#b39c00”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#a3b300”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#59b300”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#12b36b”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#00b394”,
不透明度:0.3,
国家:{
悬停:{
不透明度:1
}
}
},
{
颜色:“#00a8b3”,
opa
Highcharts.chart('container', {
chart: {
height: 800,
style: {
color: '#2e4964',
},
events: {
load() {
let chart = this;
chart.series.forEach(s => {
s.setState('inactive')
})
}
}
},
title: {
text: 'Corona',
align: 'left',
y: 20,
margin: 0,
style: {
color: '#292929',
fontWeight: '700',
fontWeight: '600',
fontSize: '22px',
fontFamily: 'Fira Sans,sans-serif'
}
},
subtitle: {
text: 'Verlauf der Pandemie in den Ländern',
align: 'left',
useHTML: true,
style: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
},
xAxis: [{
type: 'linear',
min: 1,
max: 40,
tickInterval: 5,
tickLength: 5,
labels: {
style: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
},
title: {
text: ''
}
}],
yAxis: [{
type: 'logarithmic',
max: 40000,
// minorTickInterval: 1,
min: 100,
title: {
text: null
},
labels: {
style: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
}
}],
exporting: {
buttons: {
contextButton: {
enabled: false
}
}
},
legend: {
enabled: true,
reversed: false,
title: {
text: 'Länder an- und abwählen:',
style: {
fontFamily: 'Poppins',
fontWeight: '600',
color: '#373737',
fontSize: "14px"
}
},
layout: 'horizontal',
align: 'left',
verticalAlign: 'top',
width: 300,
maxHeight: 200,
x: -8,
padding: 10,
floating: false,
borderWidth: 0,
shadow: false,
itemMarginTop: 1,
itemStyle: {
fontFamily: 'Poppins',
fontWeight: '400',
color: '#373737',
fontSize: "14px"
}
},
// tooltip: {
// shared: false,
// useHTML: true,
// headerFormat: '<span style="white-space:normal;font-size: 14px;font-weight: 400;min-width: 200px;color: black;font-family:Poppins,sans-serif">Tag {point.x}</span><br>',
// pointFormat: '<span style="color:{point.color};">● </span><span style="white-space:normal;font-size: 14px;font-weight: 400;min-width: 200px;color: black;font-family:Poppins,sans-serif;margin-top: 50px;">{series.name} : </span><span style="white-space:normal;font-size: 14px;font-weight: 800;min-width: 200px;color: black;font-family:Poppins,sans-serif">{point.y:,.0f}<br/></b></span>',
// },
tooltip: {
useHTML: true,
enabled: true,
outside: true,
formatter: function() {
return '<div style="white-space:normal;font-size: 14px;font-weight: 400;min-width: 120px;color: #373737;font-family:Poppins">' + 'Tag ' + this.x + '<br>' + this.series.name + ': <b>' + Highcharts.numberFormat(this.point.y, 0) + '</b>';
}
},
credits: {
href: '',
position: {
align: 'right',
y: -35,
},
text: 'Quellen: JHU CSSE, WHO CDC, NHC, Dingxiangyua',
style: {
cursor: 'arrow',
fontFamily: 'Poppins',
fontWeight: 'normal',
fontSize: "12px"
}
},
plotOptions: {
series: {
dataLabels: {
align: 'right',
enabled: true,
allowOverlap: true,
formatter: function() {
if (this.x == this.series.data[this.series.data.length - 1].x) {
return '<span style="color: #373737;font-weight: normal">' + Highcharts.dateFormat("%e. %B", this.x) + '</span>:<br>' + '<span style="color: #003f6e;font-weight: bold">' + Highcharts.numberFormat(this.y, 0) + '</span>';
} else {
return null;
}
},
style: {
textOutline: 0,
fontFamily: 'Poppins',
fontWeight: '400',
color: '#000',
fontSize: "12px"
}
},
marker: {
symbol: 'circle',
enabled: false
}
}
},
data: {
googleSpreadsheetKey: '13gjvlHhCZKlNcC1DV3nStGeWLBLWx3gxTO3SN9F3GQc',
complete: function(options) {
options.series[0].data.forEach(point => {
if (point[1] === 0) {
point[1] = null;
}
});
}
},
series: [{
color: '#8ebfd7',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: 'rgb(70, 151, 190)',
opacity: 0.5,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#266f9a',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#1c2b54',
opacity: 1,
dataLabels: {
enabled: true,
formatter: function() {
if (this.x == this.series.data[this.series.data.length - 1].x) {
return 'Test';
} else {
return null;
}
}
},
states: {
hover: {
opacity: 1
}
}
},
{
color: '#780081',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#9c00b3',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b3007b',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b30012',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b36d00',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#b39c00',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#a3b300',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#59b300',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#12b36b',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#00b394',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#00a8b3',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#0091b3',
opacity: 0.3,
states: {
hover: {
opacity: 1
}
}
},
{
color: '#373737',
name: 'Verdopplung alle 3 Tage',
clip: false,
dashStyle: 'dot',
showInLegend: false,
states: {
inactive: {
opacity: 1
}
},
}
]
});
dataLabels: {
enabled: true,
formatter: function() {
var visiblePoints = this.series.points.filter(p => typeof p.y === 'number');
if (this.x == visiblePoints[visiblePoints.length - 1].x) {
return 'Test';
} else {
return null;
}
}
}