我正在尝试将vue-highchartsmoment.js一起使用。

<template>
    <highcharts :constructor-type="'stockChart'" :options="stockOptions" :updateArgs="[true, false]"></highcharts>
</template>

<script>
...
    stockOptions: {
       series: [{
          data: ''
       }],
       plotOptions: {
          series: {
                turboThreshold: 0
          }
       },
       chart: {
            type: 'area'
       },
       time: {
            timezone: 'America/Sao_paulo'
       }
    }
...
</script>


但我收到此错误:

Highcharts Error #25
Can't find Moment.js library
Using the global.timezone option requires the Moment.js library to be loaded.


我该怎么做才能解决此问题?

最佳答案

Highcharts检查moment.js库是否在window范围内可用,这就是为什么您需要在其中添加它。首先,您需要导入两个模块:

import Moment from "moment";
import MomentTimeZone from "moment-timezone";


然后运行将其分配为window变量并调用moment-timezone模块函数:

window.moment = Moment
MomentTimeZone();


实时示例:https://codesandbox.io/s/n0v72938j

关于javascript - Highchart Vue-如何包含momentjs?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51487060/

10-11 12:40
查看更多