vue charts_适用于Google Charts lib的Reactive Vue.js包装器

vue charts

vue-google-charts (vue-google-charts)

Reactive Vue.js wrapper for Google Charts lib.

适用于Google Charts lib的React性Vue.js包装器。

安装 (Installation)

npm i vue-google-charts

默认导入 (Default import)

Install a component globally (use as plugin):

全局安装组件(用作插件):

import Vue from 'vue'
import VueGoogleCharts from 'vue-google-charts'

Vue.use(VueGoogleCharts)

Use locally in a component:

在组件中本地使用:

import { GChart } from 'vue-google-charts'

export default {
  components: {
    GChart
  }
}

浏览器 (Browser)

<script src="vue.js"></script>
<script src="vue-google-charts/dist/vue-google-charts.browser.js"></script>

The plugin should be auto-installed. If not, you can install it manually with the instructions below.

该插件应自动安装。 如果没有,您可以按照以下说明手动安装。

用法 (Usage)

首先阅读Google图表文档 (Read the Google Charts docs first)

The GChart component is a wrapper for the original Google Charts, so it's assumed you are familiar with the vanilla Google Charts usage (https://developers.google.com/chart/).

GChart组件是原始Google Charts的包装,因此假定您熟悉原始的Google Charts用法( https://developers.google.com/chart/ )。

With vue-google-charts package you don't need to link script loader and load Google Charts package manually.

使用vue-google-charts包,您无需链接脚本加载器并手动加载Google Charts包。

Another bonus — reactive data binding. A chart will be redrawn automatically once data or options prop is changed.

另一个好处-React性数据绑定。 更改dataoptions属性后,图表将自动重绘。

简单用法: (Simple usage:)

<GChart
    type="ColumnChart"
    :data="chartData"
    :options="chartOptions"
  />


export default {
  data () {
    return {
      // Array will be automatically processed with visualization.arrayToDataTable function
      chartData: [
        ['Year', 'Sales', 'Expenses', 'Profit'],
        ['2014', 1000, 400, 200],
        ['2015', 1170, 460, 250],
        ['2016', 660, 1120, 300],
        ['2017', 1030, 540, 350]
      ],
      chartOptions: {
        chart: {
          title: 'Company Performance',
          subtitle: 'Sales, Expenses, and Profit: 2014-2017',
        }
      }
    }
  }
}


加载其他软件包: (Load additional packages:)

<GChart
    :settings="{ packages: ['corechart', 'table', 'map'] }"
    type="Map"
    :data="chartData"
    :options="chartOptions"
  />

Using settings prop you can specify any setting available for google charts loader: packages, language, callback, mapsApiKey.

使用settings您可以指定适用于Google图表加载器的任何设置: packageslanguagecallbackmapsApiKey

See more on available setting

查看更多可用设置

There's also version prop, so you can load a specific version, e.g. version="upcoming".

还有一个version属性,因此您可以加载特定的版本,例如version="upcoming"

See more on available versions

查看更多可用版本



添加事件监听器: (Add event listeners:)

<GChart
    type="ColumnChart"
    :data="chartData"
    :options="chartOptions"
    :events="chartEvents"
  />
export default {
  data () {
    return {
      // {
      //    eventName: handlerFunction,
      //    eventName: handlerFunction,
      // }
      chartEvents: {
        'select': () => {
          // handle event here
        }
      }
    }
  }
}


用户@ready非常定制 (User @ready for something very custom)

You can get chart instance and charts api references to draw a custom chart:

您可以获取图表实例和图表API参考以绘制自定义图表:

<GChart
    type="ColumnChart"
    @ready="onChartReady"
  />
export default {
  methods: {
    onChartReady (chart, google) {
      const query = new google.visualization.Query('https://url-to-spreadsheet...')
      query.send(response => {
        const options = {
          // some custom options
        }
        const data = response.getDataTable()
        chart.draw(data, options)
      })
    }
  }
}


插件开发 (Plugin Development)

安装 (Installation)

The first time you create or clone your plugin, you need to install the default dependencies:

首次创建或克隆插件时,需要安装默认依赖项:

npm i

观看并编译 (Watch and compile)

This will run webpack in watching mode and output the compiled files in the dist folder.

这将以监视模式运行webpack,并将编译后的文件输出到dist文件夹中。

npm run dev

在另一个项目中使用 (Use it in another project)

While developing, you can follow the install instructions of your plugin and link it into the project that uses it.

在开发过程中,您可以按照插件的安装说明进行操作,并将其链接到使用该插件的项目中。

In the plugin folder:

在插件文件夹中:

npm link

In the other project folder:

在另一个项目文件夹中:

npm link vue-google-charts

This will install it in the dependencies as a symlink, so that it gets any modifications made to the plugin.

这会将其作为符号链接安装在依赖项中,以便对插件进行任何修改。

手动构建 (Manual build)

This will build the plugin into the dist folder in production mode.

这将在生产模式下将插件构建到dist文件夹中。

npm run build


翻译自: https://vuejsexamples.com/reactive-vue-js-wrapper-for-google-charts-lib/

vue charts

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这是一个 JavaScript 错误,意思是“未捕获的类型错误:(0, vue__webpack_imported_module_20__.reactive) 不是一个函数”。这通常是因为在使用 Vue.js 的响应式数据时出现了问题,可能是因为没有正确导入 Vue.js 或者没有正确使用 Vue.js 的 API。建议检查代码中是否正确导入了 Vue.js,并且是否正确使用了 Vue.js 的响应式数据 API。 ### 回答2: 这是Vue框架中的一个错误提示,在使用Vue时可能会遇到。它表示一个对象或变量在使用时,并没有正确调用Vue的反应式函数(reactive)进行声明或赋值,导致代码抛出异常。 具体来说,Vue3中的响应式函数(reactive)是一个API,用于将对象变为响应式的数据。反应式数据是指,当对象属性发生改变时,视图会自动更新展示最新数据。然而,如果在声明对象时没有正确地使用reactive函数进行声明,会导致该对象不具有响应式。 例如,在Vue中声明一个对象可以这么写: ```js const data = { count: 0 } ``` 如果此时要使其变成响应式的,需要使用Vue提供的响应式函数(reactive)将该对象包装起来,如下所示: ```js import { reactive } from 'vue' const data = reactive({ count: 0 }) ``` 这样,对象data就变成了Vue的响应式数据。然而,如果在代码中没有正确地使用reactive函数进行包装,就会遇到上述错误提示。 因此,当我们遇到“uncaught typeerror: (0 , vue__webpack_imported_module_20__.reactive) is not a function”这样的错误时,应该检查是否正确地使用了Vue提供的反应式函数(reactive)对变量或对象进行了声明。 ### 回答3: 这个错误消息 "uncaught typeerror: (0, vue__webpack_imported_module_20__.reactive) is not a function" 是 JavaScript 代码中常见的错误之一。该错误通常在使用 Vue.js 框架时出现,Vue.js 是一种流行的 JavaScript 框架,用于构建用户界面。 这个错误消息指的是代码中使用了 Vue.js 的响应式 API,但是没有正确导入 API。在 Vue.js 中,响应式 API 可以使用 Vue.createApp().use(VueCompositionAPI).mount('#app') 方法导入,但是如果没有正确导入就会出现这个错误消息。 通常,出现这个错误的主要原因是由于以下原因所导致的: 1. 没有正确安装和导入 Vue.js 2. 没有正确导入 Vue.js 中的响应式 API 3. 缺少 Vue.js 的依赖项 为了解决这个问题,需要确保安装和导入了正确的 Vue.js 版本,并正确使用 Vue.js 提供的响应式 API。如果确定安装和导入了正确的 Vue.js 版本,仍然出现这个错误,请确保在使用 Vue.js 时导入了正确的依赖项。 此外,还可以尝试使用浏览的调试工具来了解错误的更多信息,例如发生错误的代码行或导致错误的变量。通过调试工具,可以更快地找到和修复错误,并提高代码的可维护性。 总之,uncaught typeerror: (0, vue__webpack_imported_module_20__.reactive) is not a function 这个错误消息是由于没有正确导入 Vue.js 响应式 API 所导致的。为了解决这个问题,需要确保正确安装和导入 Vue.js,并使用 Vue.js 提供的正确的响应式 API。如果错误仍然存在,您可以尝试使用浏览的调试工具来进行进一步的故障排除。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值