Vuejs2 Vue Google图表-日期类型不起作用

Vuejs2 Vue Google图表-日期类型不起作用,vuejs2,google-visualization,Vuejs2,Google Visualization,可能是我,但在浏览了谷歌文档和vue谷歌图表README.md+问题之后,我仍然无法将日期作为一种日期类型 我已经尝试了下面的每一种组合,但总是得到a。getTime不是一个函数错误 我曾尝试使用v-bind:“chart”,onchartredy,并通过props,但没有成功。怎么了 <template> <div> <GChart v-bind="chart" v-on="$listeners" />

可能是我,但在浏览了谷歌文档和
vue谷歌图表
README.md+问题之后,我仍然无法将日期作为一种日期类型

我已经尝试了下面的每一种组合,但总是得到
a。getTime不是一个函数
错误

我曾尝试使用
v-bind:“chart”
onchartredy
,并通过
props
,但没有成功。怎么了

<template>
  <div>
    <GChart v-bind="chart" v-on="$listeners" />
    <!-- <GChart :type="type" @ready="onChartReady" /> -->
    <!-- <GChart :type="type" :data="dataTable" :options="chart.options" :settings="chart.settings" /> -->
  </div>
</template>

<script lang="ts">
import { Vue, Component, Prop } from 'nuxt-property-decorator'
import { GChart } from 'vue-google-charts'
import merge from 'lodash/merge'

import { GoogleChart } from '../../../shared/types'

@Component({
  components: { GChart }
})
export default class BaseChart extends Vue {
  // Core props
  @Prop({ type: String, default: GoogleChart.Type.LineChart }) type: GoogleChart.Type
  @Prop({ type: Array, required: true }) data: any[]
  @Prop({ type: Object }) options: object
  @Prop({ type: Object }) settings: object
  @Prop({ type: Number, default: 500 }) resizeDebounce: number

  get chart() {
    return {
      type: this.type,
      data: this.dataTable,
      options: merge({}, this.options, GoogleChart.Chart[this.type].options),
      settings: merge({}, this.settings, GoogleChart.Chart[this.type].settings),
      resizeDebounce: this.resizeDebounce
    }
  }

  get dataTable() {
    const [headers, ...rowData] = this.data
    const formattedHeaders = headers.map(header => ({
      label: header,
      type: header === 'Date' ? 'date' : 'number'
    }))

    const formattedRowData = rowData.map(rowData => {
      const [date, ...values] = rowData
      // Dates are formatted as 'yyyy-mm-dd'
      const [year, month, day] = date.split('-')

      // https://developers.google.com/chart/interactive/docs/reference#arraytodatatable
      //
      // return [new Date(date), ...values] // a.getTime is not a function
      // return [new Date(year, month, day), ...values] // a.getTime is not a function
      // return [`Date(${year}, ${month}, ${day})`, ...values] // a.getTime is not a function
      // return [`new Date(${year}, ${month}, ${day})`, ...values] // b.getTimezoneOffset is not a function

      // https://developers.google.com/chart/interactive/docs/reference#dateformat
      //
      const c = [{ v: new Date(date) }, ...values.map(v => ({ v })) ] // c: a.getTime is not a function, { c }: a.getTime is not a function
      // const c = [{ v: new Date(year, month, day) }, ...values.map(v => ({ v })) ] // c: a.getTime is not a function, { c }: a.getTime is not a function
      // const c = [{ v: `Date(${year}, ${month}, ${day})` }, ...values.map(v => ({ v })) ] // c: a.getTime is not a function, { c }: a.getTime is not a function
      // const c = [{ v: `new Date(${year}, ${month}, ${day})` }, ...values.map(v => ({ v })) ] // c: b.getTimezoneOffset is not a function, { c }: b.getTimezoneOffset is not a function

      // https://developers.google.com/chart/interactive/docs/reference#cell_object
      // return c
      return { c }
    })

    // https://developers.google.com/chart/interactive/docs/reference#arraytodatatable
    // return [formattedHeaders, ...formattedRowData]

    // https://developers.google.com/chart/interactive/docs/reference#cell_object
    return {
      cols: formattedHeaders,
      rows: formattedRowData
    }
  }
}
</script>

从'nuxt property decorator'导入{Vue,Component,Prop}
从“vue谷歌图表”导入{GChart}
从“lodash/merge”导入合并
从“../../../shared/types”导入{GoogleChart}
@组成部分({
组件:{GChart}
})
导出默认类BaseChart扩展Vue{
//核心道具
@属性({type:String,默认值:GoogleChart.type.LineChart})类型:GoogleChart.type
@Prop({type:Array,required:true})数据:any[]
@Prop({type:Object})选项:Object
@属性({type:Object})设置:对象
@Prop({type:Number,默认值:500})resizeDebounce:Number
获取图表(){
返回{
type:this.type,
数据:this.dataTable,
选项:合并({},this.options,GoogleChart.Chart[this.type].options),
设置:合并({},this.settings,GoogleChart.Chart[this.type].settings),
resizeDebounce:这个。resizeDebounce
}
}
获取数据表(){
const[headers,…rowData]=this.data
const formattedHeaders=headers.map(header=>({
标签:标题,
类型:标题=='Date'?'Date':'number'
}))
const formattedRowData=rowData.map(rowData=>{
常量[日期,…值]=行数据
//日期格式为“yyyy-mm-dd”
常量[年、月、日]=日期分割('-'))
// https://developers.google.com/chart/interactive/docs/reference#arraytodatatable
//
//return[new Date(Date),…values]//a.getTime不是函数
//return[新日期(年、月、日),…值]//a.getTime不是函数
//return[`Date(${year},${month},${day})`
//return[`new Date(${year},${month},${day})`
// https://developers.google.com/chart/interactive/docs/reference#dateformat
//
const c=[{v:new Date(Date)},…values.map(v=>({v}))]//c:a.getTime不是函数,{c}:a.getTime不是函数
//const c=[{v:new Date(year,month,day)},…values.map(v=>({v}))]//c:a.getTime不是函数,{c}:a.getTime不是函数
//const c=[{v:`Date(${year},${month},${day})`}
//const c=[{v:`新日期(${year},${month},${day})`}
// https://developers.google.com/chart/interactive/docs/reference#cell_object
//返回c
返回{c}
})
// https://developers.google.com/chart/interactive/docs/reference#arraytodatatable
//返回[formattedHeaders,…formattedRowData]
// https://developers.google.com/chart/interactive/docs/reference#cell_object
返回{
cols:formattedHeaders,
行:格式化的行数据
}
}
}
我可以检查并查看Vue组件上的预期数据。