• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

devstark-com/vue-google-charts: Reactive Vue.js wrapper for Google Charts lib

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

devstark-com/vue-google-charts

开源软件地址(OpenSource Url):

https://github.com/devstark-com/vue-google-charts

开源编程语言(OpenSource Language):

TypeScript 69.0%

开源软件介绍(OpenSource Introduction):

vue-google-charts

npm npm vue2 vue3

Reactive Vue.js wrapper for Google Charts lib


Installation   •   Usage   •   Slack   •   Examples

Installation

pnpm add vue-google-charts
# or
yarn add vue-google-charts
# or
npm i vue-google-charts

Need an API to fetch data? Consider Cube, an open-source API for data apps.


supported by Cube

Default import

This package works with version 2.x and 3.x of Vue.

Use locally in a component:

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

export default {
  components: {
    GChart
  }
}

For Vue 2 projects, you need to import from vue-google-charts/legacy.

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

Usage

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/).

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

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

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.

See more on available setting

There's also version prop, so you can load a specific version, e.g. 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
        }
      }
    }
  }
}

Use @ready for something very custom

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

  <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)
      })
    }
  }
}

createChart property

This property allows you to create custom chart object from outside of the component. createChart property is the function and accepts three arguments: el - the reference to chart element, google - Google chart library, type - chart type

  <GChart
    :type="chartType"
    :data="chartData"
    :options="chartOptions"
    :createChart="(el, google) => new google.charts.Bar(el)"
  />

By default the function looks like this:

  (el, google, type) => {
    return new google.visualization[type](el)
  }

For example createChart may be used to create Material bar charts (Material bar charts expect of class google.charts.Bar instead of google.visualization.BarChart). See: https://codesandbox.io/embed/z699l6oq4p?module=%2Fsrc%2FApp.vue


Responsive Chart Behaviour

GCharts are responsive by default and they can change their width on window.resize event. The resize is debounces and you can control debounce time (ms) by using resizeDebounce property:

  <GChart
    :resizeDebounce="500"
  />

If you don't need responsive behaviour for your charts, set :resizeDebounce="0"


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.

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.

npm run build

Examples

License

MIT




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap