Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/427.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Highcharts将外部变量传递给全局选项_Javascript_Highcharts - Fatal编程技术网

Javascript Highcharts将外部变量传递给全局选项

Javascript Highcharts将外部变量传递给全局选项,javascript,highcharts,Javascript,Highcharts,首次使用highcharts vue 我在我的app.js中导入了以下全局图表选项。在这里,我在导出菜单中添加了一个按钮,以利用maatwebsite/laravel excel,允许下载CSV/XLSX功能,因为最终导出将包括图表上显示的其他列(而不是通过其CSV/XSLX插件下载图表数据) 我想将url传递到图表上的导出按钮下拉列表中,但我没有成功。如何将道具(数据请求的目标url)传递到此配置 我在一个页面上有多个图表实例,每个实例都需要自己的目标url 欢迎任何建议 export con

首次使用
highcharts vue

我在我的
app.js
中导入了以下全局图表选项。在这里,我在导出菜单中添加了一个按钮,以利用
maatwebsite/laravel excel
,允许
下载CSV/XLSX
功能,因为最终导出将包括图表上显示的其他列(而不是通过其CSV/XSLX插件下载图表数据)

我想将url传递到图表上的导出按钮下拉列表中,但我没有成功。如何将道具(数据请求的目标url)传递到此配置

我在一个页面上有多个图表实例,每个实例都需要自己的目标url

欢迎任何建议

export const highChartConfig = function(page) {
    return {
        credits: {
            enabled: false
        },
        title: {
            align: 'center',
            style: {
                color: "#4B5563",
                fontSize: "16px",
                fontWeight: "300",
            },
        },
        exporting: {
            buttons: {
                contextButton: {
                    menuItems: [{
                        textKey: 'printChart',
                        onclick: function () {
                            this.print();
                        }
                    }, {
                        separator: true
                    },{
                        textKey: 'downloadCSV',
                        onclick: function () {

                            // THIS PROP I WOULD LIKE TO PASS TO THIS POINT. I GET UNDEFINED HERE
                            console.log(this.downloadCsvRoute)

                            if (this.downloadCsvRoute && this.downloadCsvRoute != '') {   
                                axios.get(this.downloadCsvRoute)
                            }
                        }
                    }]
                }
            }
        },
    }
}

onclick回调函数中的
this
关键字引用了一个图表,使用箭头函数获取外部
this
引用:

buttons: {
  contextButton: {
    menuItems: [..., {
      textKey: 'downloadCSV',
      onclick: () => {

        if (this.downloadCsvRoute && this.downloadCsvRoute != '') {
          axios.get(this.downloadCsvRoute)
        }
      }
    }]
  }
}

API参考: