首页 > 解决方案 > 使用 Higcharts 访问数组时出现问题,我如何访问 x 位置?

问题描述

我正在尝试使用 Highcharts 访问 UserOptions 传递的数组位置。

系列声明,我在其中声明数组

执行

问题是,当我尝试访问这个数组的一个元素时,它没有显示出来。

看看:

访问数组

但是,当我直接访问它并使用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]);

标签: javascriptarrayspositiontooltipoptions

解决方案


我尝试使用 formatther 并且它有效,我也发现了访问方式。

point.series.cuotasPendientes[2]我们必须使用而不是 使用point.series.cuotasPendientes.2

谢谢大家。


推荐阅读