使用 Higcharts 访问数组时出现问题,我如何访问 x 位置?
Problem accessing array using Higcharts, how may i access to x position?
我正在尝试使用 Highcharts 访问 UserOptions 传递的数组位置。
Series declaration, where i declare the array
Implementation
问题是,当我尝试访问此数组的元素时,它没有显示。
刚看到:
Accessing array
但是,当我直接访问它并使用 console.log()
打印它时,会显示此值。
console.log(a.series[1].userOptions.cuotasPendientes[5]);
Accessing directly
谢谢大家。
代码:
var a = Highcharts.chart('grafico-CIPrestamos-161107279383',{
"chart": {
"type": "column",
"style": {
"fontFamily": "Arial, Tahoma, Sans-serif",
"fontSize": "11px"
}
},
"credits": {
"enabled": false
},
"legend": {
"enabled": true,
"useHTML": true,
"itemMarginTop": 5,
"labelFormatter": function() {
return '<div class="highchartsCustom-legend-label">' + this.name + '</div>';
}
},
"title": {
"text": ""
},
"xAxis": {
"type": "datetime",
"dateTimeLabelFormats": {
"month": "%b"
},
"title": "",
"units": [
["month", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]
],
"tickInterval": 1,
"labels": {
"useHTML": true,
"format": "<span class=\"highchartsCustom-xAxis-label\">{value:%b}</span>",
"rotation": 0
},
"plotLines": [{
"color": "#ccc",
"width": 1,
"value": 1525132800000,
"dashStyle": "Dash",
"label": {
"useHTML": true,
"text": "<span class=\"highchartsCustom-xAxis-plotLine-label\">2018</span>",
"rotation": 90
}
}, {
"color": "#ccc",
"width": 1,
"value": 1546300800000,
"dashStyle": "Dash",
"label": {
"useHTML": true,
"text": "<span class=\"highchartsCustom-xAxis-plotLine-label\">2019</span>",
"rotation": 90
}
}]
},
"yAxis": {
"allowDecimals": false,
"min": 0,
"title": "",
"labels": {
"useHTML": true,
"format": "<span class=\"highchartsCustom-yAxis-label\">{value:,.0f}</span>"
},
"stackLabels": {
"enabled": false
}
},
"tooltip": {
"useHTML": true,
"headerFormat": "<table class=\"highchartsCustom-tooltip\">",
"pointFormat": "<tr><td class=\"highchartsCustom-tooltip-fecha\">{point.x:%B %Y}</td></tr><tr><td class=\"highchartsCustom-tooltip-linkedParent\">{point.series.linkedParent.name}</td></tr><tr><td class=\"highchartsCustom-tooltip-serie\">FIELD:{point.series.userOptions.cuotasPendientes[3]}</td></tr><tr><td class=\"highchartsCustom-tooltip-serie\">{point.series.name}: <span>{point.y}</span></td></tr><tr><td class=\"highchartsCustom-tooltip-total\">Total: <span>{point.stackTotal:,.0f}</span></td></tr>",
"footerFormat": "</table>",
"style": {
"padding": "1px"
}
},
"plotOptions": {
"series": {
"pointStart": 1525132800000,
"pointIntervalUnit": "month",
"pointWidth": 20,
"events": {
"legendItemClick": function(event) {
var cantidadSeleccionables = event.target.chart.series.length - 1;
if (event.target.visible && cantidadSeleccionables > contadorCIPrestamos) {
contadorCIPrestamos += 1;
return true;
}
if (!event.target.visible) {
contadorCIPrestamos -= 1;
return true;
}
return false;
}
}
},
"column": {
"stacking": "normal",
"dataLabels": {
"enabled": false
}
}
},
"series": [{
"name": "BCO 1",
"id": "BCO1",
"linkedTo": null,
"data": null,
"color": "#B07CD8",
"CuotasPendientes": null,
"vigente": "La bco es vighente",
"Estado": null,
"CapitalOriginal": 0.0,
"TotalCuotas": 0
}, {
"name": "PP1",
"id": null,
"linkedTo": "BCO1",
"data": [22.0, 23.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
"color": "#B07CD8",
"cuotasPendientes": [0, 0, 223, 223, 223, 223, 223, 223, 223, 223, 223],
"vigente": "La serie es vigente",
"Estado": null,
"CapitalOriginal": 0.0,
"TotalCuotas": 0
}],
"colors": ["#B07CD8"]})
console.log(a.series[1].userOptions.cuotasPendientes[5]);
你可以直接调用它或以这种方式循环遍历 CuotasPendientes
你的值并且不要忘记检查 CuotasPendientes
值如果它为空循环将不会处理(我已经添加了空检查) .
console.log(a.series[1].CuotasPendientes[0])
for(let i = 0 ; i < a.series.length; i++){
if (a.series[i].CuotasPendientes != null) {
for (x of a.series[i].CuotasPendientes) {
console.log(x)
}
}
}
希望对您有所帮助
我尝试使用格式化程序,它有效,我也发现了访问方式。
而不是使用
point.series.cuotasPendientes[2]
,我们必须使用point.series.cuotasPendientes.2
谢谢大家。
我正在尝试使用 Highcharts 访问 UserOptions 传递的数组位置。
Series declaration, where i declare the array
Implementation
问题是,当我尝试访问此数组的元素时,它没有显示。
刚看到:
Accessing array
但是,当我直接访问它并使用 console.log()
打印它时,会显示此值。
console.log(a.series[1].userOptions.cuotasPendientes[5]);
Accessing directly
谢谢大家。
代码:
var a = Highcharts.chart('grafico-CIPrestamos-161107279383',{
"chart": {
"type": "column",
"style": {
"fontFamily": "Arial, Tahoma, Sans-serif",
"fontSize": "11px"
}
},
"credits": {
"enabled": false
},
"legend": {
"enabled": true,
"useHTML": true,
"itemMarginTop": 5,
"labelFormatter": function() {
return '<div class="highchartsCustom-legend-label">' + this.name + '</div>';
}
},
"title": {
"text": ""
},
"xAxis": {
"type": "datetime",
"dateTimeLabelFormats": {
"month": "%b"
},
"title": "",
"units": [
["month", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]]
],
"tickInterval": 1,
"labels": {
"useHTML": true,
"format": "<span class=\"highchartsCustom-xAxis-label\">{value:%b}</span>",
"rotation": 0
},
"plotLines": [{
"color": "#ccc",
"width": 1,
"value": 1525132800000,
"dashStyle": "Dash",
"label": {
"useHTML": true,
"text": "<span class=\"highchartsCustom-xAxis-plotLine-label\">2018</span>",
"rotation": 90
}
}, {
"color": "#ccc",
"width": 1,
"value": 1546300800000,
"dashStyle": "Dash",
"label": {
"useHTML": true,
"text": "<span class=\"highchartsCustom-xAxis-plotLine-label\">2019</span>",
"rotation": 90
}
}]
},
"yAxis": {
"allowDecimals": false,
"min": 0,
"title": "",
"labels": {
"useHTML": true,
"format": "<span class=\"highchartsCustom-yAxis-label\">{value:,.0f}</span>"
},
"stackLabels": {
"enabled": false
}
},
"tooltip": {
"useHTML": true,
"headerFormat": "<table class=\"highchartsCustom-tooltip\">",
"pointFormat": "<tr><td class=\"highchartsCustom-tooltip-fecha\">{point.x:%B %Y}</td></tr><tr><td class=\"highchartsCustom-tooltip-linkedParent\">{point.series.linkedParent.name}</td></tr><tr><td class=\"highchartsCustom-tooltip-serie\">FIELD:{point.series.userOptions.cuotasPendientes[3]}</td></tr><tr><td class=\"highchartsCustom-tooltip-serie\">{point.series.name}: <span>{point.y}</span></td></tr><tr><td class=\"highchartsCustom-tooltip-total\">Total: <span>{point.stackTotal:,.0f}</span></td></tr>",
"footerFormat": "</table>",
"style": {
"padding": "1px"
}
},
"plotOptions": {
"series": {
"pointStart": 1525132800000,
"pointIntervalUnit": "month",
"pointWidth": 20,
"events": {
"legendItemClick": function(event) {
var cantidadSeleccionables = event.target.chart.series.length - 1;
if (event.target.visible && cantidadSeleccionables > contadorCIPrestamos) {
contadorCIPrestamos += 1;
return true;
}
if (!event.target.visible) {
contadorCIPrestamos -= 1;
return true;
}
return false;
}
}
},
"column": {
"stacking": "normal",
"dataLabels": {
"enabled": false
}
}
},
"series": [{
"name": "BCO 1",
"id": "BCO1",
"linkedTo": null,
"data": null,
"color": "#B07CD8",
"CuotasPendientes": null,
"vigente": "La bco es vighente",
"Estado": null,
"CapitalOriginal": 0.0,
"TotalCuotas": 0
}, {
"name": "PP1",
"id": null,
"linkedTo": "BCO1",
"data": [22.0, 23.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0],
"color": "#B07CD8",
"cuotasPendientes": [0, 0, 223, 223, 223, 223, 223, 223, 223, 223, 223],
"vigente": "La serie es vigente",
"Estado": null,
"CapitalOriginal": 0.0,
"TotalCuotas": 0
}],
"colors": ["#B07CD8"]})
console.log(a.series[1].userOptions.cuotasPendientes[5]);
你可以直接调用它或以这种方式循环遍历 CuotasPendientes
你的值并且不要忘记检查 CuotasPendientes
值如果它为空循环将不会处理(我已经添加了空检查) .
console.log(a.series[1].CuotasPendientes[0])
for(let i = 0 ; i < a.series.length; i++){
if (a.series[i].CuotasPendientes != null) {
for (x of a.series[i].CuotasPendientes) {
console.log(x)
}
}
}
希望对您有所帮助
我尝试使用格式化程序,它有效,我也发现了访问方式。
而不是使用
point.series.cuotasPendientes[2]
,我们必须使用point.series.cuotasPendientes.2
谢谢大家。