Javascript 使用Higcharts访问阵列时出现问题,如何访问x位置?
我正在尝试使用Highcharts访问UserOptions传递的数组位置 问题是,当我尝试访问这个数组的元素时,它没有显示出来 看看: 但是,当我直接访问它并使用Javascript 使用Higcharts访问阵列时出现问题,如何访问x位置?,javascript,arrays,position,tooltip,options,Javascript,Arrays,Position,Tooltip,Options,我正在尝试使用Highcharts访问UserOptions传递的数组位置 问题是,当我尝试访问这个数组的元素时,它没有显示出来 看看: 但是,当我直接访问它并使用console.log()打印它时,会显示此值 console.log(a.series[1].userOptions.cuotasPendientes[5]); 伙计们 守则: var a = Highcharts.chart('grafico-CIPrestamos-161107279383',{ "char
console.log()打印它时,会显示此值
console.log(a.series[1].userOptions.cuotasPendientes[5]);
伙计们
守则:
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]);
var a=Highcharts.chart('grafico-CIPrestamos-161107279383'{
“图表”:{
“类型”:“列”,
“风格”:{
“fontFamily”:“Arial、Tahoma、无衬线”,
“fontSize”:“11px”
}
},
“学分”:{
“已启用”:false
},
“传奇”:{
“启用”:正确,
“useHTML”:正确,
“itemMarginTop”:5,
“labelFormatter”:函数(){
返回“”+this.name+“”;
}
},
“标题”:{
“文本”:”
},
“xAxis”:{
“类型”:“日期时间”,
“dateTimeLabelFormats”:{
“月份”:“%b”
},
“名称”:“名称”,
“单位”:[
[“月”,[1,2,3,4,5,6,7,8,9,10,11,12]]
],
“滴答声间隔”:1,
“标签”:{
“useHTML”:正确,
“格式”:“{值:%b}”,
“旋转”:0
},
“绘图线”:[{
“颜色”:“ccc”,
“宽度”:1,
“价值”:1525132800000,
“dashStyle”:“Dash”,
“标签”:{
“useHTML”:正确,
“文本”:“2018年”,
“轮换”:90
}
}, {
“颜色”:“ccc”,
“宽度”:1,
“价值”:15463080000000,
“dashStyle”:“Dash”,
“标签”:{
“useHTML”:正确,
“文本”:“2019年”,
“轮换”:90
}
}]
},
“yAxis”:{
“allowDecimals”:false,
“min”:0,
“名称”:“名称”,
“标签”:{
“useHTML”:正确,
格式“{value:,.0f}”
},
“堆叠标签”:{
“已启用”:false
}
},
“工具提示”:{
“useHTML”:正确,
“人头税”:“,
“pointFormat:“{point.x:%B%Y}{point.series.linkedParent.name}字段:{point.series.userOptions.cuotsapendentes[3]}{point.series.name}:{point.Y}总计:{point.stackTotal:,.0f}”,
“页脚格式”:“,
“风格”:{
“填充”:“1px”
}
},
“打印选项”:{
“系列”:{
“起点”:1525132800000,
“pointIntervalUnit”:“月份”,
“点宽度”:20,
“事件”:{
“legendItemClick”:函数(事件){
var cantidadSeleccionables=event.target.chart.series.length-1;
if(event.target.visible&&cantidadseleccinables>contadorCIPrestamos){
CONTADORECIPRESTAMOS+=1;
返回true;
}
如果(!event.target.visible){
contadorCIPrestamos-=1;
返回true;
}
返回false;
}
}
},
“列”:{
“堆叠”:“正常”,
“数据标签”:{
“已启用”:false
}
}
},
“系列”:[{
“名称”:“BCO 1”,
“id”:“BCO1”,
“linkedTo”:空,
“数据”:空,
“颜色”:“#B07CD8”,
“cuotaspendentes”:空,
“vigente”:“La bco es vighente”,
“Estado”:空,
“资本原始”:0.0,
“TotalCuotas”:0
}, {
“名称”:“PP1”,
“id”:空,
“linkedTo”:“BCO1”,
“数据”:[22.0,23.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0],
“颜色”:“#B07CD8”,
“Cuotaspendentes”:[0,0,223,223,223,223,223,223,223,223,223,223],
“维根特”:“意甲维根特”,
“Estado”:空,
“资本原始”:0.0,
“TotalCuotas”:0
}],
“颜色”:[“#B07CD8”]})
log(a.series[1].userOptions.cuotaspendentes[5]);
u可以直接调用它或通过cuotsapendentes
ur值以这种方式循环,并且不要忘记检查cuotsapendentes
值,如果它为null,循环将不会处理(我已经添加了null检查)
console.log(a.series[1].cuotaspendentes[0])
for(设i=0;i
希望它能帮上忙我试过使用formatther,效果很好,而且我也介绍了访问的方法
而不是使用
point.series.cuotaspendentes[2]
,我们必须使用point.series.cuotaspendentes.2
谢谢大家。你能给我们一些经过编辑的代码吗?你能刷新页面吗?ThnxI正在尝试以工具提示点格式访问。Higcharts需要以下格式的纯文本:数组的元素:{point.series.userOptions[3]}我不能在这个实例中迭代。你能创建一个JSFIDLE吗?顺便说一下,在你的工具提示中,你可以在那里使用格式化程序,你能正确格式化你的值吗?你试过formatter吗?我试过formatter,它很有效,而且我也发现了访问的方法。point.series.cuotaspendentes.x,其中x是位置。这是小提琴:
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)
}
}
}