Feature/v3 (#225)
* Remove Vue dependency and change extends Signed-off-by: Jakub Juszczak <netghost03@gmail.com> * 💎 Release new version 3.0.0-rc0 * ⬆️ Update examples * 📝 Update README.md * ⬆️ Update examples * ⬆️ Update englishd docs * ⬆️ Update transalted docs with current code examples * 🔥 Remove dist files from gitignore * ⬆️ Update dependencies vue and chartjs * Change private data Implements #182. The private chart instance is now in the vue.js data model. And can be accessed over `this.$data._chart` Updated unit tests * 📝 Update docs with private data * ✨ Add codeclimate ignore * ⬆️ Update codeclimate * ⬆️ Update codeclimate * ⬆️ Update codeclimate Add build and config folders to ignore
@@ -30,12 +30,13 @@ You can import the whole package or each module individual.
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart(data, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
You can pass two arguments to the `renderChart()` method:
|
||||
@@ -86,12 +87,13 @@ You can create data and options props to pass data to the chart.
|
||||
// LineChart.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
After you add your component you can use it:
|
||||
@@ -121,7 +123,8 @@ If you want to overwrite width and height:
|
||||
```javascript
|
||||
import {Bar} from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
data () {
|
||||
return {
|
||||
datacollection: {
|
||||
@@ -139,7 +142,7 @@ export default Bar.extend({
|
||||
mounted () {
|
||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### Reusable Components
|
||||
@@ -172,7 +175,8 @@ data () {
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ['options'],
|
||||
mounted () {
|
||||
@@ -180,7 +184,7 @@ export default Line.extend({
|
||||
// If you want to pass options please create a local options object
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**RandomChart.vue**
|
||||
@@ -254,7 +258,7 @@ export default Line.extend({
|
||||
|
||||
## Chart.js object
|
||||
|
||||
Sometimes you need more control over Chart.js. That's why you can access the Chart.js instance over `this._chart`.
|
||||
Sometimes you need more control over Chart.js. That's why you can access the Chart.js instance over `this.$data._chart`.
|
||||
|
||||
## Inline plugins
|
||||
|
||||
|
||||
BIN
docs/assets/bar.png
Normal file → Executable file
|
Before Width: | Height: | Size: 95 KiB After Width: | Height: | Size: 25 KiB |
BIN
docs/assets/bubble.png
Normal file → Executable file
|
Before Width: | Height: | Size: 83 KiB After Width: | Height: | Size: 26 KiB |
BIN
docs/assets/doughnut.png
Normal file → Executable file
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 41 KiB |
BIN
docs/assets/line.png
Normal file → Executable file
|
Before Width: | Height: | Size: 125 KiB After Width: | Height: | Size: 31 KiB |
BIN
docs/assets/pie.png
Normal file → Executable file
|
Before Width: | Height: | Size: 97 KiB After Width: | Height: | Size: 76 KiB |
BIN
docs/assets/polar.png
Normal file → Executable file
|
Before Width: | Height: | Size: 200 KiB After Width: | Height: | Size: 87 KiB |
BIN
docs/assets/radar.png
Normal file → Executable file
|
Before Width: | Height: | Size: 180 KiB After Width: | Height: | Size: 75 KiB |
0
docs/assets/scatter.png
Normal file → Executable file
|
Before Width: | Height: | Size: 43 KiB After Width: | Height: | Size: 43 KiB |
@@ -41,7 +41,7 @@ docute.init({
|
||||
apiKey: 'b3544f7387612693644777553675d56a',
|
||||
indexName: 'vue-chartjs',
|
||||
// algolia docsearch allows you to search with tag filter
|
||||
tags: ['en', 'de', 'fr', 'ja', 'pt-br', 'ru'],
|
||||
tags: ['en', 'fr', 'ja', 'pt-br', 'ru'],
|
||||
// this plugin does require a url too
|
||||
// where docsearch fetches contents
|
||||
url: 'https://vue-chartjs.org'
|
||||
|
||||
@@ -1,311 +0,0 @@
|
||||
---
|
||||
search: de
|
||||
---
|
||||
|
||||
# vue-chartjs
|
||||
**vue-chartjs** ist ein Wrapper für [Chart.js](https://github.com/chartjs/Chart.js) in vue. Man kann einfach wiederverwendbare Chart Components erstellen.
|
||||
|
||||
## Einleitung
|
||||
`vue-chartjs` let you use chart.js without much hassle inside vue. It's perfect for people who need simple charts up and running as fast as possible.
|
||||
|
||||
It abstracts the basic logic but exposes the chart.js object to give you the most possible flexibility.
|
||||
|
||||
## Installation
|
||||
If you are working with Vue.js 2+ simple run:
|
||||
|
||||
`yarn add vue-chartjs chart.js`
|
||||
|
||||
If you are using vue 1.x please use the `legacy` tag. However the vue 1 version is not maintained anymore.
|
||||
|
||||
`yarn add vue-chartjs@legacy`
|
||||
|
||||
## Schnellstart
|
||||
|
||||
You need to import the base chart and extend it. This gives much more flexibility when working with different data.
|
||||
You can encapsulate your components and use props to pass data or you can directly imput them inside the component. However this way, your component is not reuseable.
|
||||
|
||||
You can import the whole package or each module individual.
|
||||
|
||||
```javascript
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart(data, options)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
You can pass the `renderChart()` method, two arguments:
|
||||
|
||||
- Data object
|
||||
- Options object
|
||||
|
||||
### Data object
|
||||
|
||||
The data object looks like this:
|
||||
|
||||
```javascript
|
||||
{
|
||||
labels: ['January', 'February'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'GitHub Commits',
|
||||
backgroundColor: '#f87979',
|
||||
data: [40, 20]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
For more information take a look at the [Chart.js](http://www.chartjs.org/docs/#chart-configuration-chart-data) docs.
|
||||
|
||||
## Props
|
||||
|
||||
There are some basic props defined in the BaseCharts. Because you `extend()` them, they are *invisible*, but you can overwrite them:
|
||||
|
||||
| Prop | Description |
|
||||
|---|---|
|
||||
| width | chart width |
|
||||
| height | chart height |
|
||||
| chart-id | id of the canvas |
|
||||
|
||||
|
||||
## Examples
|
||||
|
||||
Here are some exmaples
|
||||
|
||||
### Chart with props
|
||||
|
||||
You can create the data and options props to pass data to the chart.
|
||||
|
||||
```javascript
|
||||
// LineChart.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
After you add your component you can use it:
|
||||
|
||||
```html
|
||||
<line-chart :data="{your data object}" :options="{your options}"></line-chart>
|
||||
```
|
||||
|
||||
If you want to overwrite the width and height:
|
||||
|
||||
```html
|
||||
<line-chart
|
||||
:data="{your data object}"
|
||||
:options="{responsive: false, maintainAspectRatio: false}"
|
||||
:width="400"
|
||||
:height="200"
|
||||
>
|
||||
</line-chart>
|
||||
```
|
||||
|
||||
<p class="warning">
|
||||
Please keep in mind, that you have to set `responsive: false` to be able to set a fix `width` and `height.
|
||||
</p>
|
||||
|
||||
### Chart with local data
|
||||
|
||||
```javascript
|
||||
import {Bar} from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
data () {
|
||||
return {
|
||||
datacollection: {
|
||||
labels: ['January', 'February'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Data One',
|
||||
backgroundColor: '#f87979',
|
||||
data: [40, 20]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
### Reusebale Components
|
||||
|
||||
If you want to keep your chart components reuseable, it's the best to add a wrapper to them. This way the chart component is only responsable for the pure data representation and the wrapper component for the logic behind it. There are many different usecases and it is different if you're running a Single Page Application or integrate it in for example laravel.
|
||||
|
||||
## Reactive Data
|
||||
|
||||
Chart.js does not provide a live update if you change the datasets. However `vue-chartjs` provides two mixins to achive this.
|
||||
|
||||
- `reactiveProp`
|
||||
- `reactiveData`
|
||||
|
||||
Both mixins to actually the same. Most of the time you will use `reactiveProp`. It extends the logic of your chart component and automatically creates a prop names `chartData` and add a `vue watch` on this prop. On data change, it will either call `update()` if only the data inside the datasets has changed or `renderChart()` if new datasets were added.
|
||||
|
||||
`reactiveData` simply creates a local chartData variable which is not a prop! And add a watcher.
|
||||
This is only usefull, if you need single purpose charts and make an API call inside your chart component.
|
||||
|
||||
```javascript
|
||||
data () {
|
||||
return {
|
||||
chartData: null
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Example
|
||||
|
||||
**LineChart.js**
|
||||
```javascript
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
mixins: [reactiveProp],
|
||||
props: ['options'],
|
||||
mounted () {
|
||||
// this.chartData is created in the mixin
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
**RandomChart.vue**
|
||||
|
||||
```javascript
|
||||
<template>
|
||||
<div class="small">
|
||||
<line-chart :chart-data="datacollection"></line-chart>
|
||||
<button @click="fillData()">Randomize</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import LineChart from './LineChart.js'
|
||||
|
||||
export default {
|
||||
components: {
|
||||
LineChart
|
||||
},
|
||||
data () {
|
||||
return {
|
||||
datacollection: null
|
||||
}
|
||||
},
|
||||
mounted () {
|
||||
this.fillData()
|
||||
},
|
||||
methods: {
|
||||
fillData () {
|
||||
this.datacollection = {
|
||||
labels: [this.getRandomInt(), this.getRandomInt()],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Data One',
|
||||
backgroundColor: '#f87979',
|
||||
data: [this.getRandomInt(), this.getRandomInt()]
|
||||
}, {
|
||||
label: 'Data One',
|
||||
backgroundColor: '#f87979',
|
||||
data: [this.getRandomInt(), this.getRandomInt()]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
getRandomInt () {
|
||||
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.small {
|
||||
max-width: 600px;
|
||||
margin: 150px auto;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
||||
<p class="warning">
|
||||
⚠ Attention: If you mutate your data in a parent component and pass it to your child chart component keep in mind the javascript limitiations.
|
||||
More info in this [issue#44](https://github.com/apertureless/vue-chartjs/issues/44)
|
||||
</p>
|
||||
|
||||
### Limitations
|
||||
<ul>
|
||||
<li>[Caveats](https://vuejs.org/v2/guide/list.html#Caveats)</li>
|
||||
<li>[Change-Detection-Caveats](https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats)</li>
|
||||
<li>[vm.$watch](https://vuejs.org/v2/api/#vm-watch)</li>
|
||||
</ul>
|
||||
|
||||
## Chart.js object
|
||||
|
||||
Sometimes you need more control over chart.js. Thats why you can access the chart.js instance over `this._chart`
|
||||
|
||||
## Available Charts
|
||||
|
||||
### Bar Chart
|
||||
<p class="tip">
|
||||
There are two versions of the Bar chart. `{Bar}` and `{HorizontalBar}`
|
||||
</p>
|
||||
|
||||

|
||||
### Line Chart
|
||||
|
||||

|
||||
|
||||
### Doughnut
|
||||
|
||||

|
||||
|
||||
### Pie
|
||||
|
||||

|
||||
|
||||
### Radar
|
||||
|
||||

|
||||
|
||||
### Polar Area
|
||||
|
||||

|
||||
|
||||
### Bubble
|
||||
|
||||

|
||||
|
||||
## Webpack, Browserify and dist files.
|
||||
|
||||
If you use `import VueCharts from 'vue-chartjs'` you will mostly import the UMD build of vue-chart.js
|
||||
This is because of compatibility reasons. This approach however has a downside: vue.js and chart.js are bundled into the file.
|
||||
And you end up with two vue instances.
|
||||
|
||||
If you're using webpack 2 or rollup however, it will automatically import the transpiled ES sources.
|
||||
If you know what you're doing you can import directly from the transpiled es sources:
|
||||
|
||||
```
|
||||
import { Line } from 'vue-chartjs/es'
|
||||
```
|
||||
|
||||
### Browserify
|
||||
|
||||
In order for a browserify user to transpile the code, they would need to install `babelify` and `babel-preset-es2015` and add a .babelrc file in the root of their project with the following code:
|
||||
|
||||
```
|
||||
{
|
||||
"presets": ["es2015"]
|
||||
}
|
||||
```
|
||||
@@ -30,12 +30,13 @@ Vous pouvez choisir d'importer le package dans son intégralité, ou chaque comp
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Surcharge de la méthode render avec les données.
|
||||
this.renderChart(data, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
La méthode `renderChart()` prend deux paramètres :
|
||||
@@ -86,12 +87,13 @@ Vous pouvez créer les props data et options à transmetttre au graphe.
|
||||
// LineChart.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Vous pourrez les utiliser après avoir ajouté votre composant :
|
||||
@@ -121,7 +123,8 @@ Vous devrez préciser `responsive: false` si vous souhaitez appliquer une taille
|
||||
```javascript
|
||||
import {Bar} from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
data () {
|
||||
return {
|
||||
datacollection: {
|
||||
@@ -139,7 +142,7 @@ export default Bar.extend({
|
||||
mounted () {
|
||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### Composants réutilisables
|
||||
@@ -174,7 +177,8 @@ data () {
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ['options'],
|
||||
mounted () {
|
||||
@@ -182,7 +186,7 @@ export default Line.extend({
|
||||
// si vous voulez transmettre des options, il faudra créer une variable locale
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**RandomChart.vue**
|
||||
@@ -256,7 +260,7 @@ export default Line.extend({
|
||||
|
||||
## Objet Chart.js
|
||||
|
||||
Il peut arriver d'avoir besoin de plus de contrôle sur l'objet chart.js. Vous pouvez, à cet effet, accéder à cet objet via `this._chart`.
|
||||
Il peut arriver d'avoir besoin de plus de contrôle sur l'objet chart.js. Vous pouvez, à cet effet, accéder à cet objet via `this.$data._chart`.
|
||||
|
||||
## Plugins inline
|
||||
|
||||
|
||||
@@ -31,12 +31,13 @@ Kamu bisa meng-import seluruh package atau modul-modul terpisah.
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart(data, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Kamu dapat melewatkan dua argumen pada `renderChart()`:
|
||||
@@ -87,12 +88,13 @@ Kamu dapat membuat props data dan opsi untuk melewatkan data pada chart.
|
||||
// LineChart.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Setelah kamu menambahkannya kamu dapat menggunakannya seperti biasa:
|
||||
@@ -122,7 +124,8 @@ Jika kamu ingin mengatur tinggi dan lebar:
|
||||
```javascript
|
||||
import {Bar} from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
data () {
|
||||
return {
|
||||
datacollection: {
|
||||
@@ -140,7 +143,7 @@ export default Bar.extend({
|
||||
mounted () {
|
||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### Reusable Komponen
|
||||
@@ -173,7 +176,8 @@ data () {
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ['options'],
|
||||
mounted () {
|
||||
@@ -181,7 +185,7 @@ export default Line.extend({
|
||||
// If you want to pass options please create a local options object
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**RandomChart.vue**
|
||||
@@ -255,7 +259,7 @@ export default Line.extend({
|
||||
|
||||
## Objek Chart.js
|
||||
|
||||
Suatu ketika kamu membutuhkan kontrol chart.js. Kamu dapat mengaksesnya dengan `this._chart`
|
||||
Suatu ketika kamu membutuhkan kontrol chart.js. Kamu dapat mengaksesnya dengan `this.$data._chart`
|
||||
|
||||
## Inline plugins
|
||||
|
||||
|
||||
@@ -32,12 +32,13 @@ BaseChartをインポートしてextendします。
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart(data, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
renderChart()メソッドに2つの引数を渡すことができます:
|
||||
@@ -86,12 +87,13 @@ dataとoptionsプロパティを作成して、チャートにデータを渡す
|
||||
// LineChart.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
コンポーネントに追加して、使用することができます。
|
||||
@@ -121,7 +123,8 @@ export default Line.extend({
|
||||
```javascript
|
||||
import {Bar} from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
data () {
|
||||
return {
|
||||
datacollection: {
|
||||
@@ -139,7 +142,7 @@ export default Bar.extend({
|
||||
mounted () {
|
||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### コンポーネントの再利用
|
||||
@@ -174,14 +177,15 @@ data () {
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ['options'],
|
||||
mounted () {
|
||||
// this.chartData is created in the mixin
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**RandomChart.vue**
|
||||
@@ -255,7 +259,7 @@ export default Line.extend({
|
||||
|
||||
## Chart.js オブジェクト
|
||||
|
||||
場合によっては、chart.jsをより詳細に制御する必要があります。Chart.jsインスタンスには `this._chart` を使ってアクセスします。
|
||||
場合によっては、chart.jsをより詳細に制御する必要があります。Chart.jsインスタンスには `this.$data._chart` を使ってアクセスします。
|
||||
|
||||
## 利用可能なグラフ
|
||||
|
||||
|
||||
@@ -90,7 +90,8 @@ Apenas crie seu próprio componente.
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart({
|
||||
@@ -104,7 +105,7 @@ export default Bar.extend({
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Então, simplesmente importe e use seu próprio componente extendido como um componente vue.
|
||||
@@ -121,12 +122,13 @@ Você pode sobreescrever as options (opções) padrão do gráfico. Basta passar
|
||||
// MonthlyIncome.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ["data", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Use isso no seu componente vue
|
||||
@@ -163,13 +165,14 @@ Os mixins criam automaticamente o `chartData` como um prop ou como um data. E ad
|
||||
// MonthlyIncome.js
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [mixins.reactiveProp],
|
||||
props: ["chartData", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -181,26 +184,28 @@ Algumas maneiras de importá-los:
|
||||
// Load complete module with all charts
|
||||
import VueCharts from 'vue-chartjs'
|
||||
|
||||
export default VueCharts.Line.extend({
|
||||
export default {
|
||||
extends: VueCharts.Line,
|
||||
mixins: [VueCharts.mixins.reactiveProp],
|
||||
props: ["chartData", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Load speperate modules
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [mixins.reactiveProp],
|
||||
props: ["chartData", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
@@ -208,13 +213,14 @@ export default Line.extend({
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ["chartData", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Gráficos disponíveis
|
||||
|
||||
@@ -81,7 +81,7 @@ search: ru
|
||||
|
||||
## Как использовать
|
||||
|
||||
Вам необходимо импортировать базовый класс диаграммы и унаследовать его. Это даст гораздо большую гибкость при работе с различными данными. Вы можете передать данные через props или vue-resource.
|
||||
Вам необходимо импортировать базовый класс диаграммы и унаследовать его. Это даст гораздо большую гибкость при работе с различными данными. Вы можете передать данные через props или vue-resource.
|
||||
|
||||
Вы можете импортировать весь проект или каждый модуль по отдельности.
|
||||
|
||||
@@ -96,7 +96,8 @@ import { Bar, Line } from 'vue-chartjs'
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Переопределение базового рендер метода с реальными данными.
|
||||
this.renderChart({
|
||||
@@ -110,7 +111,7 @@ export default Bar.extend({
|
||||
]
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Затем просто импортируйте и используйте ваши собственные расширенные компоненты как обычные vue компоненты.
|
||||
@@ -127,12 +128,13 @@ import CommitChart from 'path/to/component/CommitChart'
|
||||
// MonthlyIncome.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
Используйте это в вашем vue приложении
|
||||
@@ -169,13 +171,14 @@ Chart.js не обновляет и не перерисовывает диагр
|
||||
// MonthlyIncome.js
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [mixins.reactiveProp],
|
||||
props: ['chartData', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
@@ -187,26 +190,28 @@ export default Line.extend({
|
||||
// Load complete module with all charts
|
||||
import VueCharts from 'vue-chartjs'
|
||||
|
||||
export default VueCharts.Line.extend({
|
||||
export default {
|
||||
extends: VueCharts.Line,
|
||||
mixins: [VueCharts.mixins.reactiveProp],
|
||||
props: ['chartData', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
// Load speperate modules
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [mixins.reactiveProp],
|
||||
props: ['chartData', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
```javascript
|
||||
@@ -214,13 +219,14 @@ export default Line.extend({
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ['chartData', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
## Доступные диаграммы
|
||||
|
||||
@@ -31,12 +31,13 @@ search: zh-cn
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart(data, options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
你可以给 `renderChart()` 方法传递两个参数:
|
||||
@@ -86,12 +87,13 @@ export default Bar.extend({
|
||||
// LineChart.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
props: ['data', 'options'],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
然后你可以把它作为组件使用。
|
||||
@@ -121,7 +123,8 @@ export default Line.extend({
|
||||
```javascript
|
||||
import {Bar} from 'vue-chartjs'
|
||||
|
||||
export default Bar.extend({
|
||||
export default {
|
||||
extends: Bar,
|
||||
data () {
|
||||
return {
|
||||
datacollection: {
|
||||
@@ -139,7 +142,7 @@ export default Bar.extend({
|
||||
mounted () {
|
||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
### 可复用的组件
|
||||
@@ -172,14 +175,15 @@ data () {
|
||||
import { Line, mixins } from 'vue-chartjs'
|
||||
const { reactiveProp } = mixins
|
||||
|
||||
export default Line.extend({
|
||||
export default {
|
||||
extends: Line,
|
||||
mixins: [reactiveProp],
|
||||
props: ['options'],
|
||||
mounted () {
|
||||
// this.chartData is created in the mixin
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
**RandomChart.vue**
|
||||
@@ -253,7 +257,7 @@ export default Line.extend({
|
||||
|
||||
## Chart.js 对象
|
||||
|
||||
有时你需要更多的调整 chart.js。你可以访问 `this._chart` 实例。
|
||||
有时你需要更多的调整 chart.js。你可以访问 `this.$data._chart` 实例。
|
||||
|
||||
## 内联插件
|
||||
|
||||
|
||||