Highchart Vue-如何包含momentjs?

Kel*_*nda 0 javascript highcharts momentjs vue.js

我想用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>
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

Highcharts Error #25
Can't find Moment.js library
Using the global.timezone option requires the Moment.js library to be loaded.
Run Code Online (Sandbox Code Playgroud)

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

dan*_*l_s 6

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

import Moment from "moment";
import MomentTimeZone from "moment-timezone";
Run Code Online (Sandbox Code Playgroud)

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

window.moment = Moment
MomentTimeZone();
Run Code Online (Sandbox Code Playgroud)

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