Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b465070a7a | ||
|
|
d498b7c8cf | ||
|
|
0fa8261664 | ||
|
|
653b4d7580 | ||
|
|
8b52bae9c1 | ||
|
|
b8012b9944 | ||
|
|
4b363b3e29 | ||
|
|
b46d193caf | ||
|
|
831a70574f | ||
|
|
a6593910ac | ||
|
|
892c5ed2ab | ||
|
|
3451769a65 | ||
|
|
7e5bf7d9bc | ||
|
|
58523d6155 | ||
|
|
b71cd6c2eb | ||
|
|
3fea6f413b | ||
|
|
fcd9071f9a | ||
|
|
37a92813eb | ||
|
|
1260b8aa3b | ||
|
|
644859ce85 | ||
|
|
e4977a6be7 | ||
|
|
41736c840d | ||
|
|
4c37616d00 | ||
|
|
5dc655a47a | ||
|
|
3d291996f6 | ||
|
|
750abb2e88 | ||
|
|
46569a89cb | ||
|
|
932b73a1dc | ||
|
|
0569a9f794 | ||
|
|
154e284528 | ||
|
|
491625b49b | ||
|
|
d26078f08c | ||
|
|
6de69631b3 | ||
|
|
82712948e9 | ||
|
|
9237fa538f | ||
|
|
82c502cf45 | ||
|
|
676a60a363 | ||
|
|
f60f87c141 | ||
|
|
b7f2bf7db2 | ||
|
|
0e419886b1 | ||
|
|
f95ea49a19 | ||
|
|
1e392091ea | ||
|
|
4bf4f5736c | ||
|
|
703a91dafa | ||
|
|
d68af61dce | ||
|
|
0fbdcc10b0 | ||
|
|
ab31dfe727 | ||
|
|
a5b58c3b98 | ||
|
|
85fafd9b58 | ||
|
|
54d85da955 | ||
|
|
6d19370687 |
18
.codeclimate.yml
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
engines:
|
||||||
|
eslint:
|
||||||
|
enabled: true
|
||||||
|
duplication:
|
||||||
|
enabled: true
|
||||||
|
config:
|
||||||
|
languages:
|
||||||
|
- javascript:
|
||||||
|
ratings:
|
||||||
|
paths:
|
||||||
|
- "**.js"
|
||||||
|
exclude_paths:
|
||||||
|
- "dist/"
|
||||||
|
- "test/**/*"
|
||||||
|
- "es/"
|
||||||
|
- "build/"
|
||||||
|
- "config/"
|
||||||
|
- "src/examples/**"
|
||||||
1
.gitignore
vendored
@@ -4,5 +4,4 @@ npm-debug.log
|
|||||||
selenium-debug.log
|
selenium-debug.log
|
||||||
test/unit/coverage
|
test/unit/coverage
|
||||||
test/e2e/reports
|
test/e2e/reports
|
||||||
dist/
|
|
||||||
es/
|
es/
|
||||||
|
|||||||
94
CHANGELOG.md
@@ -1,5 +1,99 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## [v2.8.5](https://github.com/apertureless/vue-chartjs/tree/v2.8.5) (2017-09-12)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.8.4...v2.8.5)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- TypeError: Cannot convert undefined or null to object [\#193](https://github.com/apertureless/vue-chartjs/issues/193)
|
||||||
|
- Chart error since the addition of deepmerge in build 2.8.4 [\#192](https://github.com/apertureless/vue-chartjs/issues/192)
|
||||||
|
|
||||||
|
## [v2.8.4](https://github.com/apertureless/vue-chartjs/tree/v2.8.4) (2017-09-08)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.8.3...v2.8.4)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Regression in 2.8.3 [\#190](https://github.com/apertureless/vue-chartjs/issues/190)
|
||||||
|
- Why default Chart.js styles are overridden? [\#189](https://github.com/apertureless/vue-chartjs/issues/189)
|
||||||
|
- Legend or other options not working in reactiveProps [\#188](https://github.com/apertureless/vue-chartjs/issues/188)
|
||||||
|
- Changes to yAxisID property does not re-render chart [\#177](https://github.com/apertureless/vue-chartjs/issues/177)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Replace Object.assign with deepmerge [\#191](https://github.com/apertureless/vue-chartjs/pull/191) ([apertureless](https://github.com/apertureless))
|
||||||
|
|
||||||
|
## [v2.8.3](https://github.com/apertureless/vue-chartjs/tree/v2.8.3) (2017-09-06)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.8.2...v2.8.3)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Rounded corner for Bar chart [\#185](https://github.com/apertureless/vue-chartjs/issues/185)
|
||||||
|
- Access canvas object from parents [\#184](https://github.com/apertureless/vue-chartjs/issues/184)
|
||||||
|
- Issue with DonutChart in Safari [\#183](https://github.com/apertureless/vue-chartjs/issues/183)
|
||||||
|
- Responsive Width, Fixed Height [\#180](https://github.com/apertureless/vue-chartjs/issues/180)
|
||||||
|
- Entire Lodash Library Is Loaded!! 200kb chunk! [\#179](https://github.com/apertureless/vue-chartjs/issues/179)
|
||||||
|
- height changed unexpectedly after re-rendering [\#178](https://github.com/apertureless/vue-chartjs/issues/178)
|
||||||
|
- Default height no longer working in 2.8 [\#176](https://github.com/apertureless/vue-chartjs/issues/176)
|
||||||
|
- how to get click on point in bar chart? [\#175](https://github.com/apertureless/vue-chartjs/issues/175)
|
||||||
|
- clean install of from npm cannot be used in gulp / browserify [\#174](https://github.com/apertureless/vue-chartjs/issues/174)
|
||||||
|
- tooltip callbacks possible? [\#173](https://github.com/apertureless/vue-chartjs/issues/173)
|
||||||
|
- Computed object won't populate chart [\#170](https://github.com/apertureless/vue-chartjs/issues/170)
|
||||||
|
- Error in nextTick: "RangeError: Maximum call stack size exceeded" [\#169](https://github.com/apertureless/vue-chartjs/issues/169)
|
||||||
|
- Standalone chartjs build \(don't include moment.js\) [\#124](https://github.com/apertureless/vue-chartjs/issues/124)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- 🔥 Remove default styles object as it causes problems [\#187](https://github.com/apertureless/vue-chartjs/pull/187) ([apertureless](https://github.com/apertureless))
|
||||||
|
- remvove lodash merge [\#186](https://github.com/apertureless/vue-chartjs/pull/186) ([apertureless](https://github.com/apertureless))
|
||||||
|
|
||||||
|
## [v2.8.2](https://github.com/apertureless/vue-chartjs/tree/v2.8.2) (2017-08-12)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.8.1...v2.8.2)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- UNMET PEER DEPENDENCY [\#167](https://github.com/apertureless/vue-chartjs/issues/167)
|
||||||
|
- Base Charts' height: 200% [\#164](https://github.com/apertureless/vue-chartjs/issues/164)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Add support for xLabels and yLabels [\#166](https://github.com/apertureless/vue-chartjs/pull/166) ([dsbert](https://github.com/dsbert))
|
||||||
|
- Update README.md [\#165](https://github.com/apertureless/vue-chartjs/pull/165) ([mikeybeck](https://github.com/mikeybeck))
|
||||||
|
|
||||||
|
## [v2.8.1](https://github.com/apertureless/vue-chartjs/tree/v2.8.1) (2017-08-05)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.8.0...v2.8.1)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Add Russian documentation [\#163](https://github.com/apertureless/vue-chartjs/pull/163) ([dood-](https://github.com/dood-))
|
||||||
|
|
||||||
|
## [v2.8.0](https://github.com/apertureless/vue-chartjs/tree/v2.8.0) (2017-08-04)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v1.2.0...v2.8.0)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- Update README CDN link [\#161](https://github.com/apertureless/vue-chartjs/issues/161)
|
||||||
|
- Options being ignored [\#160](https://github.com/apertureless/vue-chartjs/issues/160)
|
||||||
|
- Fails to dynamically change height. [\#158](https://github.com/apertureless/vue-chartjs/issues/158)
|
||||||
|
- Chart doesn't load in bootstrap tab [\#157](https://github.com/apertureless/vue-chartjs/issues/157)
|
||||||
|
- Add scatter chart to vue-chatjs@legacy [\#155](https://github.com/apertureless/vue-chartjs/issues/155)
|
||||||
|
- \[Error\] Get error when $destroy is started. [\#149](https://github.com/apertureless/vue-chartjs/issues/149)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Feature/dynamic styles [\#162](https://github.com/apertureless/vue-chartjs/pull/162) ([apertureless](https://github.com/apertureless))
|
||||||
|
- Add Chinese simplified docs support. [\#159](https://github.com/apertureless/vue-chartjs/pull/159) ([Mooooooon](https://github.com/Mooooooon))
|
||||||
|
|
||||||
|
## [v1.2.0](https://github.com/apertureless/vue-chartjs/tree/v1.2.0) (2017-07-25)
|
||||||
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.7.2...v1.2.0)
|
||||||
|
|
||||||
|
**Closed issues:**
|
||||||
|
|
||||||
|
- this.$refs doesn't seem to have expected canvas property [\#156](https://github.com/apertureless/vue-chartjs/issues/156)
|
||||||
|
|
||||||
|
**Merged pull requests:**
|
||||||
|
|
||||||
|
- Before destroy fix [\#152](https://github.com/apertureless/vue-chartjs/pull/152) ([DenisLapi](https://github.com/DenisLapi))
|
||||||
|
|
||||||
## [v2.7.2](https://github.com/apertureless/vue-chartjs/tree/v2.7.2) (2017-07-22)
|
## [v2.7.2](https://github.com/apertureless/vue-chartjs/tree/v2.7.2) (2017-07-22)
|
||||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.7.1...v2.7.2)
|
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.7.1...v2.7.2)
|
||||||
|
|
||||||
|
|||||||
75
README.md
@@ -40,7 +40,7 @@ Or if you want to use it directly in the browser add
|
|||||||
```html
|
```html
|
||||||
<script src="https://unpkg.com/vue-chartjs/dist/vue-chartjs.full.min.js"></script>
|
<script src="https://unpkg.com/vue-chartjs/dist/vue-chartjs.full.min.js"></script>
|
||||||
```
|
```
|
||||||
to your scripts. See [Codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010)
|
to your scripts. See [Codepen](https://codepen.io/apertureless/pen/zEvvWM)
|
||||||
|
|
||||||
## Explanation of Different Builds
|
## Explanation of Different Builds
|
||||||
There are three different entry points. It depends on which build setup do you have. The dependencies are bundled or required as a peerDependency.
|
There are three different entry points. It depends on which build setup do you have. The dependencies are bundled or required as a peerDependency.
|
||||||
@@ -49,33 +49,52 @@ There are three different entry points. It depends on which build setup do you h
|
|||||||
- Browserify / Webpack 1
|
- Browserify / Webpack 1
|
||||||
- Webpack 2
|
- Webpack 2
|
||||||
|
|
||||||
|
| Build | Chart.js |
|
||||||
| Build | Chart.js | Vue.js |
|
|
||||||
|---|---|---|
|
|---|---|---|
|
||||||
| vue-chartjs.full.js | Bundled | Bundled |
|
| vue-chartjs.full.js | Bundled |
|
||||||
| vue-chartjs.full.min.js | Bundled | Bundled |
|
| vue-chartjs.full.min.js | Bundled |
|
||||||
| vue-chartjs.js | peerDependency | peerDependency |
|
| vue-chartjs.js | peerDependency |
|
||||||
| vue-chartjs.min.js | peerDependency | peerDependency |
|
| vue-chartjs.min.js | peerDependency |
|
||||||
| es/index* | peerDependency | peerDependency |
|
| es/index* | peerDependency |
|
||||||
|
|
||||||
### Browser
|
### Browser
|
||||||
You can use `vue-chartjs` directly in the browser without any build setup. Like in this [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). For this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Vue.js and Chart.js bundled into it. And bundled to a UMD Module. So you only need that one file.
|
You can use `vue-chartjs` directly in the browser without any build setup. Like in this [codepen](https://codepen.io/apertureless/pen/zEvvWM). For this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Chart.js bundled into it. And bundled to a UMD Module. So you only need that one file.
|
||||||
|
|
||||||
|
You can then simply register your component:
|
||||||
|
|
||||||
|
```js
|
||||||
|
Vue.component('line-chart', {
|
||||||
|
extends: VueChartJs.Line,
|
||||||
|
mounted () {
|
||||||
|
this.renderChart({
|
||||||
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Data One',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [40, 39, 10, 40, 39, 80, 40]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Browserify / Webpack 1
|
### Browserify / Webpack 1
|
||||||
|
|
||||||
If you're using Gulp, Browserify or Webpack 1 the entry is `vue-chartjs.js` which is __transpiled__ and __bundled__ UMD Module.
|
If you're using Gulp, Browserify or Webpack 1 the entry is `vue-chartjs.js` which is __transpiled__ and __bundled__ UMD Module.
|
||||||
|
|
||||||
However Vue.js and Chart.js are `deerDependencies` so you have to install them seperately. In most projects you will have `Vue.js` already installed anyways. This way, you can have different versions of Vue.js and Chart.js then in this package.
|
However Chart.js is a `peerDependencies` so you have to install it separately. In most projects This way, you can have different versions of Chart.js then in this package.
|
||||||
|
|
||||||
### Webpack 2
|
### Webpack 2
|
||||||
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point. Which is `es/index.js`
|
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point. Which is `es/index.js`
|
||||||
It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way you three shaking will work. Like in the bundled version, `Vue.js` and `Chart.js` are `peerDependencies` and need to be installed.
|
It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way you three shaking will work. Like in the bundled version, `Chart.js` is a `peerDependencies` and need to be installed.
|
||||||
|
|
||||||
|
|
||||||
## How to use
|
## How to use
|
||||||
|
|
||||||
You need to import the base chart class and extend it. This gives much more flexibility when working with different data. You can pass the data over props or vue-resource.
|
You need to import the component and then either use `extends` or `mixins` and add it.
|
||||||
|
|
||||||
You can import the whole package or each module individual.
|
You can import the whole package or each module individual.
|
||||||
|
|
||||||
@@ -90,7 +109,8 @@ Just create your own component.
|
|||||||
// CommitChart.js
|
// CommitChart.js
|
||||||
import { Bar } from 'vue-chartjs'
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mounted () {
|
mounted () {
|
||||||
// Overwriting base render method with actual data.
|
// Overwriting base render method with actual data.
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
@@ -104,7 +124,7 @@ export default Bar.extend({
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Then simply import and use your own extended component and use it like a normal vue component
|
Then simply import and use your own extended component and use it like a normal vue component
|
||||||
@@ -118,15 +138,16 @@ import CommitChart from 'path/to/component/CommitChart'
|
|||||||
You can overwrite the default chart options. Just pass the options object as a second paramenter to the render method
|
You can overwrite the default chart options. Just pass the options object as a second paramenter to the render method
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// MonthlyIncome.js
|
// MonthlyIncome.vue
|
||||||
import { Line } from 'vue-chartjs'
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
props: ['data', 'options'],
|
props: ['data', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.data, this.options)
|
this.renderChart(this.data, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Use it in your vue app
|
Use it in your vue app
|
||||||
@@ -163,13 +184,14 @@ However keep in mind the limitations of vue and javascript for mutations on arra
|
|||||||
// MonthlyIncome.js
|
// MonthlyIncome.js
|
||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [mixins.reactiveProp],
|
mixins: [mixins.reactiveProp],
|
||||||
props: ['chartData', 'options'],
|
props: ['chartData', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -181,26 +203,28 @@ Some ways to import them:
|
|||||||
// Load complete module with all charts
|
// Load complete module with all charts
|
||||||
import VueCharts from 'vue-chartjs'
|
import VueCharts from 'vue-chartjs'
|
||||||
|
|
||||||
export default VueCharts.Line.extend({
|
export default {
|
||||||
|
extends: VueCharts.Line,
|
||||||
mixins: [VueCharts.mixins.reactiveProp],
|
mixins: [VueCharts.mixins.reactiveProp],
|
||||||
props: ['chartData', 'options'],
|
props: ['chartData', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Load speperate modules
|
// Load speperate modules
|
||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [mixins.reactiveProp],
|
mixins: [mixins.reactiveProp],
|
||||||
props: ['chartData', 'options'],
|
props: ['chartData', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -208,13 +232,14 @@ export default Line.extend({
|
|||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
const { reactiveProp } = mixins
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [reactiveProp],
|
mixins: [reactiveProp],
|
||||||
props: ['chartData', 'options'],
|
props: ['chartData', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Available Charts
|
## Available Charts
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ module.exports = {
|
|||||||
umdNamedDefine: true
|
umdNamedDefine: true
|
||||||
},
|
},
|
||||||
externals: {
|
externals: {
|
||||||
'vue': 'vue',
|
|
||||||
'chart.js': 'chart.js'
|
'chart.js': 'chart.js'
|
||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
|
|||||||
34010
dist/vue-chartjs.full.js
vendored
Normal file
13
dist/vue-chartjs.full.min.js
vendored
Normal file
3974
dist/vue-chartjs.js
vendored
Normal file
2
dist/vue-chartjs.min.js
vendored
Normal file
@@ -3,26 +3,26 @@ search: en
|
|||||||
---
|
---
|
||||||
|
|
||||||
# vue-chartjs
|
# vue-chartjs
|
||||||
**vue-chartjs** is a wrapper for [Chart.js](https://github.com/chartjs/Chart.js) in vue. You can easily create reuseable chart components.
|
**vue-chartjs** is a wrapper for [Chart.js](https://github.com/chartjs/Chart.js) in Vue. You can easily create reusable chart components.
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
`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.
|
`vue-chartjs` lets 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.
|
It abstracts the basic logic but exposes the Chart.js object to give you maximal flexibility.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
If you are working with Vue.js 2+ simple run:
|
If you are working with Vue.js 2+ simple run:
|
||||||
|
|
||||||
`yarn add vue-chartjs chart.js`
|
`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.
|
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`
|
`yarn add vue-chartjs@legacy`
|
||||||
|
|
||||||
## Quick Start
|
## Quick Start
|
||||||
|
|
||||||
You need to import the base chart and extend it. This gives much more flexibility when working with different data.
|
You need to import the base chart and extend it. This gives 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 encapsulate your components and use props to pass data or you can input them directly inside the component. However your component is not reusable this way.
|
||||||
|
|
||||||
You can import the whole package or each module individual.
|
You can import the whole package or each module individual.
|
||||||
|
|
||||||
@@ -30,15 +30,16 @@ You can import the whole package or each module individual.
|
|||||||
// CommitChart.js
|
// CommitChart.js
|
||||||
import { Bar } from 'vue-chartjs'
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mounted () {
|
mounted () {
|
||||||
// Overwriting base render method with actual data.
|
// Overwriting base render method with actual data.
|
||||||
this.renderChart(data, options)
|
this.renderChart(data, options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
You can pass the `renderChart()` method, two arguments:
|
You can pass two arguments to the `renderChart()` method:
|
||||||
|
|
||||||
- Data object
|
- Data object
|
||||||
- Options object
|
- Options object
|
||||||
@@ -80,18 +81,19 @@ Here are some exmaples
|
|||||||
|
|
||||||
### Chart with props
|
### Chart with props
|
||||||
|
|
||||||
You can create the data and options props to pass data to the chart.
|
You can create data and options props to pass data to the chart.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// LineChart.js
|
// LineChart.js
|
||||||
import { Line } from 'vue-chartjs'
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
props: ['data', 'options'],
|
props: ['data', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.data, this.options)
|
this.renderChart(this.data, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
After you add your component you can use it:
|
After you add your component you can use it:
|
||||||
@@ -100,7 +102,7 @@ After you add your component you can use it:
|
|||||||
<line-chart :data="{your data object}" :options="{your options}"></line-chart>
|
<line-chart :data="{your data object}" :options="{your options}"></line-chart>
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to overwrite the width and height:
|
If you want to overwrite width and height:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<line-chart
|
<line-chart
|
||||||
@@ -113,7 +115,7 @@ If you want to overwrite the width and height:
|
|||||||
```
|
```
|
||||||
|
|
||||||
<p class="warning">
|
<p class="warning">
|
||||||
Please keep in mind, that you have to set `responsive: false` to be able to set a fix `width` and `height`.
|
Please keep in mind, that you have to set `responsive: false` to be able to set a fixed `width` and `height`.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
### Chart with local data
|
### Chart with local data
|
||||||
@@ -121,7 +123,8 @@ If you want to overwrite the width and height:
|
|||||||
```javascript
|
```javascript
|
||||||
import {Bar} from 'vue-chartjs'
|
import {Bar} from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
datacollection: {
|
datacollection: {
|
||||||
@@ -139,24 +142,23 @@ export default Bar.extend({
|
|||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Reusebale Components
|
### Reusable 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.
|
If you want to keep your chart components reusable, it's the best to add a wrapper to them. This way the chart component is only responsible for the pure data representation and the wrapper component for the logic behind it. There are many different use cases and it is different if you're running a single page application or integrate it in for example laravel.
|
||||||
|
|
||||||
## Reactive Data
|
## Reactive Data
|
||||||
|
|
||||||
Chart.js does not provide a live update if you change the datasets. However `vue-chartjs` provides two mixins to achive this.
|
Chart.js does not provide a live update if you change the datasets. However `vue-chartjs` provides two mixins to achieve this.
|
||||||
|
|
||||||
- `reactiveProp`
|
- `reactiveProp`
|
||||||
- `reactiveData`
|
- `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.
|
Both mixins do actually achieve the same. Most of the time you will use `reactiveProp`. It extends the logic of your chart component and automatically creates a prop named `chartData` and adds 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.
|
`reactiveData` simply creates a local chartData variable which is not a prop! and adds a watcher. This is only useful, if you need single purpose charts and make an API call inside your chart component.
|
||||||
This is only usefull, if you need single purpose charts and make an API call inside your chart component.
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
data () {
|
data () {
|
||||||
@@ -173,7 +175,8 @@ data () {
|
|||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
const { reactiveProp } = mixins
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [reactiveProp],
|
mixins: [reactiveProp],
|
||||||
props: ['options'],
|
props: ['options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
@@ -181,7 +184,7 @@ export default Line.extend({
|
|||||||
// If you want to pass options please create a local options object
|
// If you want to pass options please create a local options object
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**RandomChart.vue**
|
**RandomChart.vue**
|
||||||
@@ -242,7 +245,7 @@ export default Line.extend({
|
|||||||
```
|
```
|
||||||
|
|
||||||
<p class="warning">
|
<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.
|
⚠ Attention: If you mutate your data in a parent component and pass it to your child chart component keep the javascript limitations in mind.
|
||||||
More info in this [issue#44](https://github.com/apertureless/vue-chartjs/issues/44)
|
More info in this [issue#44](https://github.com/apertureless/vue-chartjs/issues/44)
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
@@ -255,11 +258,11 @@ export default Line.extend({
|
|||||||
|
|
||||||
## Chart.js object
|
## Chart.js object
|
||||||
|
|
||||||
Sometimes you need more control over chart.js. Thats 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
|
## Inline plugins
|
||||||
|
|
||||||
In Chart.js you can define global and inline plugins. Global plugins are working without problems with `vue-chartjs` like in the [chart.js docs](http://www.chartjs.org/docs/latest/developers/plugins.html) described.
|
In Chart.js you can define global and inline plugins. Global plugins are working without problems with `vue-chartjs` like in the [Chart.js docs](http://www.chartjs.org/docs/latest/developers/plugins.html) described.
|
||||||
|
|
||||||
If you want to add inline plugins, `vue-chartjs` exposes a helper method called `addPlugin()`
|
If you want to add inline plugins, `vue-chartjs` exposes a helper method called `addPlugin()`
|
||||||
You should call `addPlugin()` before the `renderChart()` method.
|
You should call `addPlugin()` before the `renderChart()` method.
|
||||||
@@ -281,7 +284,7 @@ mounted () {
|
|||||||
|
|
||||||
### Bar Chart
|
### Bar Chart
|
||||||
<p class="tip">
|
<p class="tip">
|
||||||
There are two versions of the Bar chart. `{Bar}` and `{HorizontalBar}`
|
There are two versions of the Bar chart: `{Bar}` and `{HorizontalBar}`
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||

|

|
||||||
@@ -311,13 +314,13 @@ mounted () {
|
|||||||
|
|
||||||
### Scatter
|
### Scatter
|
||||||
|
|
||||||
This chart has a different data structure then the others. Right now the reactive Mixins are not working for this chart type.
|
This chart has a different data structure then the others. Right now the reactive mixins are not working for this chart type.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Explanation of Different Builds
|
## Explanation of Different Builds
|
||||||
There are three different entry points. It depends on which build setup do you have. The dependencies are bundled or required as a peerDependency.
|
There are three different entry points. It depends on your build setup. The dependencies are bundled or required as a peerDependency.
|
||||||
|
|
||||||
- Browser
|
- Browser
|
||||||
- Browserify / Webpack 1
|
- Browserify / Webpack 1
|
||||||
@@ -333,22 +336,21 @@ There are three different entry points. It depends on which build setup do you h
|
|||||||
| es/index* | peerDependency | peerDependency |
|
| es/index* | peerDependency | peerDependency |
|
||||||
|
|
||||||
### Browser
|
### Browser
|
||||||
You can use `vue-chartjs` directly in the browser without any build setup. Like in this [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). For this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Vue.js and Chart.js bundled into it. And bundled to a UMD Module. So you only need that one file.
|
You can use `vue-chartjs` directly in the browser without any build setup, like in this [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). In this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Vue.js and Chart.js bundled into it and is bundled to a UMD module, so you only need that one file.
|
||||||
|
|
||||||
|
|
||||||
### Browserify / Webpack 1
|
### Browserify / Webpack 1
|
||||||
|
|
||||||
If you're using Gulp, Browserify or Webpack 1 the entry is `vue-chartjs.js` which is __transpiled__ and __bundled__ UMD Module.
|
If you're using Gulp, Browserify or Webpack 1 the entry is `vue-chartjs.js` which is __transpiled__ and __bundled__ UMD Module.
|
||||||
|
|
||||||
However Vue.js and Chart.js are `peerDependencies` so you have to install them seperately. In most projects you will have `Vue.js` already installed anyways. This way, you can have different versions of Vue.js and Chart.js then in this package.
|
However Vue.js and Chart.js are `peerDependencies` so you have to install them separately. In most projects you will have Vue.js already installed anyways. This way, you can have different versions of Vue.js and Chart.js then in this package.
|
||||||
|
|
||||||
### Webpack 2
|
### Webpack 2
|
||||||
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point. Which is `es/index.js`
|
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point, which is `es/index.js`. It is a __transpiled__ es version of the source and is not __bundled__ to a module. This way your tree shaking will work. Like in the bundled version, Vue.js and Chart.js are `peerDependencies` and need to be installed.
|
||||||
It is a __transpiled__ es version of the source. And is not __bundled__ to a module. This way your tree shaking will work. Like in the bundled version, `Vue.js` and `Chart.js` are `peerDependencies` and need to be installed.
|
|
||||||
|
|
||||||
## Resources
|
## Resources
|
||||||
|
|
||||||
You can find here some Resources like tutorials on how to use `vue-chartjs`
|
You can find here some resources like tutorials on how to use `vue-chartjs`
|
||||||
|
|
||||||
- [Using vue-chartjs with WordPress](https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f)
|
- [Using vue-chartjs with WordPress](https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f)
|
||||||
- [Create stunning Charts with Vue and Chart.js](https://hackernoon.com/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a)
|
- [Create stunning Charts with Vue and Chart.js](https://hackernoon.com/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a)
|
||||||
|
|||||||
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 |
BIN
docs/assets/scatter.png
Executable file
|
After Width: | Height: | Size: 43 KiB |
@@ -1,9 +1,12 @@
|
|||||||
const langs = [
|
const langs = [
|
||||||
{title: 'English', path: '/home', matchPath: /^\/(home|changelog)/},
|
{title: 'English', path: '/home', matchPath: /^\/(home|changelog)/},
|
||||||
{title: 'Deutsch', path: '/de/', matchPath: /^\/de/},
|
{title: 'Deutsch', path: '/de/', matchPath: /^\/de/},
|
||||||
|
{title: 'Français', path: '/fr-fr/', matchPath: /^\/fr-fr/},
|
||||||
{title: '日本語', path: '/ja/', matchPath: /^\/ja/},
|
{title: '日本語', path: '/ja/', matchPath: /^\/ja/},
|
||||||
{title: 'Português do Brasil', path: '/pt-br/', matchPath: /^\/pt-br/},
|
{title: 'Português do Brasil', path: '/pt-br/', matchPath: /^\/pt-br/},
|
||||||
{title: '中文(简体)', path: '/zh-cn/', matchPath: /^\/zh-cn/}
|
{title: '中文(简体)', path: '/zh-cn/', matchPath: /^\/zh-cn/},
|
||||||
|
{title: 'Русский', path: '/ru/', matchPath: /^\/ru/},
|
||||||
|
{title: 'Bahasa Indonesia', path: '/id/', matchPath: /^\/ru/}
|
||||||
]
|
]
|
||||||
|
|
||||||
docute.init({
|
docute.init({
|
||||||
@@ -38,7 +41,7 @@ docute.init({
|
|||||||
apiKey: 'b3544f7387612693644777553675d56a',
|
apiKey: 'b3544f7387612693644777553675d56a',
|
||||||
indexName: 'vue-chartjs',
|
indexName: 'vue-chartjs',
|
||||||
// algolia docsearch allows you to search with tag filter
|
// algolia docsearch allows you to search with tag filter
|
||||||
tags: ['en', 'de', 'ja', 'pt-br'],
|
tags: ['en', 'fr', 'ja', 'pt-br', 'ru'],
|
||||||
// this plugin does require a url too
|
// this plugin does require a url too
|
||||||
// where docsearch fetches contents
|
// where docsearch fetches contents
|
||||||
url: 'https://vue-chartjs.org'
|
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"]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
366
docs/fr-fr/README.md
Normal file
@@ -0,0 +1,366 @@
|
|||||||
|
---
|
||||||
|
search: fr-fr
|
||||||
|
---
|
||||||
|
|
||||||
|
# vue-chartjs
|
||||||
|
**vue-chartjs** is a wrapper for [Chart.js](https://github.com/chartjs/Chart.js) in vue. You can easily create reuseable chart components.
|
||||||
|
|
||||||
|
## Introduction
|
||||||
|
`vue-chartjs` vous permet d'utiliser chart.js avec vue sans prise de tête. C'est la solution idéale pour ceux qui souhaitent créer des graphes simplement et rapidement.
|
||||||
|
|
||||||
|
La logique interne de chart.js est abstraite, mais l'objet sous-jacent est exposé, de sorte que vous puissiez bénéficier de la plus grande flexibilité possible.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
Si vous travaillez avec Vue.js 2+, exécutez simplement :
|
||||||
|
|
||||||
|
`yarn add vue-chartjs chart.js`
|
||||||
|
|
||||||
|
Avec vue 1.x, il vous faudra utiliser le marqueur `legacy`. Notez toutefois que la version 1 de vue n'est plus maintenue à l'heure actuelle.
|
||||||
|
|
||||||
|
`yarn add vue-chartjs@legacy`
|
||||||
|
|
||||||
|
## Démarrage rapide
|
||||||
|
|
||||||
|
Importez l'objet graphe de base afin de l'étendre. Cette façon de faire offre beaucoup plus de flexibilité lorsque plusieurs sources de données sont utilisées.
|
||||||
|
Il est possible d'encapsuler vos composants et d'utiliser les props pour transmettre les données, ou vous pouvez également les indiquer directement à l'intérieur du composant. Cependant, cette seconde méthode ne créera pas des composants réutilisables.
|
||||||
|
|
||||||
|
Vous pouvez choisir d'importer le package dans son intégralité, ou chaque composant individuellement.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// CommitChart.js
|
||||||
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
|
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 :
|
||||||
|
|
||||||
|
- un objet de données
|
||||||
|
- un objet d'options
|
||||||
|
|
||||||
|
### Objet de données
|
||||||
|
|
||||||
|
L'objet de données prend la structure suivante :
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
labels: ['Janvier', 'Février'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Commits sur GitHub',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [40, 20]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Pour plus d'informations, vous pouvez lire la documentation [Chart.js](http://www.chartjs.org/docs/#chart-configuration-chart-data).
|
||||||
|
|
||||||
|
## Props
|
||||||
|
|
||||||
|
Certains props de base sont définis dans BaseCharts. Grâce à l'héritage de l'opération `extend()`, ceux-ci peuvent être surchargés, bien qu'ils soient *invisibles*.
|
||||||
|
|
||||||
|
| Prop | Description |
|
||||||
|
|---|---|
|
||||||
|
| width | largeur du graphe |
|
||||||
|
| height | hauteur du graphe |
|
||||||
|
| chart-id | id du canvas |
|
||||||
|
| css-classes | Chaîne de caractères avec les classes CSS à appliquer à l'élément div parent |
|
||||||
|
| styles | Object avec les styles CSS à appliquer à l'élément div parent |
|
||||||
|
|
||||||
|
## Exemples
|
||||||
|
|
||||||
|
Voici quelques exemples.
|
||||||
|
|
||||||
|
### Graphe avec props
|
||||||
|
|
||||||
|
Vous pouvez créer les props data et options à transmetttre au graphe.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// LineChart.js
|
||||||
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
props: ['data', 'options'],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.data, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Vous pourrez les utiliser après avoir ajouté votre composant :
|
||||||
|
|
||||||
|
```html
|
||||||
|
<line-chart :data="{votre objet de données}" :options="{vos options}"></line-chart>
|
||||||
|
```
|
||||||
|
|
||||||
|
Si vous souhaitez modifier la hauteur ou la largeur :
|
||||||
|
|
||||||
|
```html
|
||||||
|
<line-chart
|
||||||
|
:data="{votre objet de données}"
|
||||||
|
:options="{responsive: false, maintainAspectRatio: false}"
|
||||||
|
:width="400"
|
||||||
|
:height="200"
|
||||||
|
>
|
||||||
|
</line-chart>
|
||||||
|
```
|
||||||
|
|
||||||
|
<p class="warning">
|
||||||
|
Vous devrez préciser `responsive: false` si vous souhaitez appliquer une taille fixe avec `width` et `height`.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
### Graphe avec données locales
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import {Bar} from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Bar,
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
datacollection: {
|
||||||
|
labels: ['Janvier', 'Février'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Data One',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [40, 20]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Composants réutilisables
|
||||||
|
|
||||||
|
Si vous souhaitez faire en sorte que vos composants restent réutilisables, le mieux est de leur appliquer un wrapper. De cette manière, le composant graphique est seulement responsable de la représentation de la donnée, alors que le wrapper se charge de la logique derrière elle. Il y a de nombreux cas d'utilisations, et la manière de faire sera différente si vous êtes sur une Application Monopage (SPA) ou si vous intégrez sur du Laravel par exemple.
|
||||||
|
|
||||||
|
## Données en direct
|
||||||
|
|
||||||
|
Chart.js ne fournit pas de mécanisme de mise à jour automatique si jamais vous deviez modifier vos jeux de données. Cependant, `vue-chartjs` met à disposition deux mixins pour cela :
|
||||||
|
|
||||||
|
- `reactiveProp`
|
||||||
|
- `reactiveData`
|
||||||
|
|
||||||
|
Tous deux réalisent le même travail. La plupart du temps, c'est `reactiveProp` que vous utiliserez. Il reprend la logique de votre composant graphique, et crée automatiquement une prop `chartData` et ajoute une `vue watch` sur celle-ci. Lorsque la donnée change, `update()` sera appelée si c'est seulement le coeur de la donnée qui est modifié, et `renderChart()` si de nouveaux jeux de données ont été ajoutés.
|
||||||
|
|
||||||
|
`reactiveData` crée une variable locale chartData (pas une prop !), et lui ajoute un watcher.
|
||||||
|
Le seul cas d'utilisation est celui où vous souhaitez un graphe à usage unique, et que vous effectuez des appels API à l'intérieur même du composant.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
chartData: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Exemple
|
||||||
|
|
||||||
|
**LineChart.js**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
mixins: [reactiveProp],
|
||||||
|
props: ['options'],
|
||||||
|
mounted () {
|
||||||
|
// this.chartData est créé par le mixin.
|
||||||
|
// si vous voulez transmettre des options, il faudra créer une variable locale
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**RandomChart.vue**
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
<template>
|
||||||
|
<div class="small">
|
||||||
|
<line-chart :chart-data="datacollection"></line-chart>
|
||||||
|
<button @click="fillData()">Aléatoire</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 : si vous permutez vos données dans un composant parent puis les transmettez à un composant enfant, gardez à l'esprit les limitations de javascript.
|
||||||
|
Plus d'infos sur [issue#44](https://github.com/apertureless/vue-chartjs/issues/44).
|
||||||
|
</p>
|
||||||
|
|
||||||
|
### Limitations
|
||||||
|
<ul>
|
||||||
|
<li>[Mises en garde](https://vuejs.org/v2/guide/list.html#Caveats)</li>
|
||||||
|
<li>[Mise en garde sur la détection des modifications](https://vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats)</li>
|
||||||
|
<li>[vm.$watch](https://vuejs.org/v2/api/#vm-watch)</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
## 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.$data._chart`.
|
||||||
|
|
||||||
|
## Plugins inline
|
||||||
|
|
||||||
|
Avec Chart.js, vous pouvez définir des pugins globaux ou inline. Les plugins globaux fonctionnent sans souci avec `vue-chartjs`, comme décrit dans la [documentation chart.js](http://www.chartjs.org/docs/latest/developers/plugins.html) described.
|
||||||
|
|
||||||
|
Si vous désirez ajouter des plugins inline, `vue-chartjs` expose une méthode `addPlugin()`. L'appel à cette méthode doit se faire avant celui de `renderChart()`.
|
||||||
|
|
||||||
|
### Exemple
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
mounted () {
|
||||||
|
this.addPlugin({
|
||||||
|
id: 'mon-plugin',
|
||||||
|
beforeInit: function (chart) {
|
||||||
|
....
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Diagrammes disponibles
|
||||||
|
|
||||||
|
### Colonnes
|
||||||
|
|
||||||
|
<p class="tip">
|
||||||
|
Il y a deux versions du diagramme colonnes : `{Bar}` et `{HorizontalBar}`
|
||||||
|
</p>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Ligne
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Beignet
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Circulaire
|
||||||
|
|
||||||
|

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

|
||||||
|
|
||||||
|
### Polaire
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Bulles
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
### Nuages de points
|
||||||
|
|
||||||
|
Ce diagramme utilise une structure de données différente des autres. Pour le moment, les mixis de mise à jour de données ne fonctionnent pas avec ce type de graphique.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## Explications sur les différents builds
|
||||||
|
|
||||||
|
Il y a trois builds différents. Le choix dépend de votre projet. Les dépendances sont soient intégrées, soit marquées comme peerDependency.
|
||||||
|
|
||||||
|
- Browser
|
||||||
|
- Browserify / Webpack 1
|
||||||
|
- Webpack 2
|
||||||
|
|
||||||
|
|
||||||
|
| Build | Chart.js | Vue.js |
|
||||||
|
|---|---|---|
|
||||||
|
| vue-chartjs.full.js | Intégré | Intégré |
|
||||||
|
| vue-chartjs.full.min.js | Intégré | Intégré |
|
||||||
|
| vue-chartjs.js | peerDependency | peerDependency |
|
||||||
|
| vue-chartjs.min.js | peerDependency | peerDependency |
|
||||||
|
| es/index* | peerDependency | peerDependency |
|
||||||
|
|
||||||
|
### Browser
|
||||||
|
|
||||||
|
Vous pouvez utiliser `vue-chartjs` directement depuis votre navigateur sans aucun pré-requis. Comme par exemple sur ce [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). Dans une telle situation, veuillez utiliser `vue-chartjs.full.min.js`, qui est la version compressée. Elle intègre Vue.js et Chart.js, et est bundlée à un module UMD. Donc ce fichier se suffit à lui-même.
|
||||||
|
|
||||||
|
|
||||||
|
### Browserify / Webpack 1
|
||||||
|
|
||||||
|
Si vous utilisez Gulp, Browserify ou Webpack 1, vous devrez prendre `vue-chartjs.js`, qui est __transpilé__ et __bundlé__ comme module UMD.
|
||||||
|
|
||||||
|
Toutefois, Vue.js et Chart.js sont des `peerDependencies`, vous devrez donc les installer séparemment. Dans la plupart des projets, `Vue.js` sera de toute façon déjà installé. De cette manière, vous pouvez utiliser des versions différentes de Vue.js et Chart.js dans un même package.
|
||||||
|
|
||||||
|
### Webpack 2
|
||||||
|
|
||||||
|
Si vous utilisez Webpack 2, `jsnext:main` / `module` sera automatiquement sélectionné. `es/index.js`est une version es __transpilée__ des sources, et n'est pas __bundlée__ à un module. Ainsi, rien ne devrait bloquer l'élimination de code mort. Comme dans la version bundlée précédente, `Vue.js` et `Chart.js` sont des `peerDependencies` et doivent être installés.
|
||||||
|
|
||||||
|
## Ressources
|
||||||
|
|
||||||
|
Voici une liste de ressources et tutoriels sur comment utiliser `vue-chartjs` :
|
||||||
|
|
||||||
|
- [Using vue-chartjs with WordPress](https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f)
|
||||||
|
- [Create stunning Charts with Vue and Chart.js](https://hackernoon.com/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a)
|
||||||
|
- [Let’s Build a Web App with Vue, Chart.js and an API Part I](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44)
|
||||||
|
- [Let’s Build a Web App with Vue, Chart.js and an API Part II](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf)
|
||||||
|
- [Build a realtime chart with VueJS and Pusher](https://blog.pusher.com/build-realtime-chart-with-vuejs-pusher/)
|
||||||
363
docs/id/README.md
Normal file
@@ -0,0 +1,363 @@
|
|||||||
|
---
|
||||||
|
search: id
|
||||||
|
---
|
||||||
|
|
||||||
|
# vue-chartjs
|
||||||
|
**vue-chartjs** adalah wrapper [Chart.js](https://github.com/chartjs/Chart.js) dalam vue. Kamu dapat dengan mudah membuat komponen chart reusable.
|
||||||
|
|
||||||
|
## Pengenalan
|
||||||
|
`vue-chartjs` memungkinkan kamu untuk menggunakan chart.js tanpa usaha lebih didalam vue. Sempurna untuk orang-orang yang membutuhkan bagan/chart simpel dengan cepat.
|
||||||
|
|
||||||
|
Flexibel karena langsung menampilkan objek chart.js.
|
||||||
|
|
||||||
|
|
||||||
|
## Instalasi
|
||||||
|
Jika kamu menggunakan Vue.js 2+:
|
||||||
|
|
||||||
|
`yarn add vue-chartjs chart.js`
|
||||||
|
|
||||||
|
Jika menggunakan vue 1.x gunakan tag `legacy`. versi vue 1 sudah tidak diurus lagi.
|
||||||
|
|
||||||
|
`yarn add vue-chartjs@legacy`
|
||||||
|
|
||||||
|
## Mulai Cepat
|
||||||
|
|
||||||
|
Kamu perlu untuk meng-import base chart dan meng-extend-nya. Dengan cara ini akan lebih fleksibel ketika bekerja dengan data yang berbeda.
|
||||||
|
Kamu dapat melakukan enkapsulasi komponen-komponen dan menggunakan props untuk menyampaikan data atau bisa juga dengan menginputkan langsung didalam komponen. Namun komponenmu tidak reuseable.
|
||||||
|
|
||||||
|
Kamu bisa meng-import seluruh package atau modul-modul terpisah.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// CommitChart.js
|
||||||
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Bar,
|
||||||
|
mounted () {
|
||||||
|
// Overwriting base render method with actual data.
|
||||||
|
this.renderChart(data, options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Kamu dapat melewatkan dua argumen pada `renderChart()`:
|
||||||
|
|
||||||
|
- Objek Data
|
||||||
|
- Objek Opsi
|
||||||
|
|
||||||
|
### Data object
|
||||||
|
|
||||||
|
Objek data:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
labels: ['January', 'February'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'GitHub Commits',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [40, 20]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Untuk keterangan lebih lanjut dapat dilihat di dokumentasi [Chart.js](http://www.chartjs.org/docs/#chart-configuration-chart-data).
|
||||||
|
|
||||||
|
## Props
|
||||||
|
|
||||||
|
Terdapat beberapa props standar yang didefinisikan didalam BaseChart. Karena menggunakan `extend()`, props-props tersebut *tidak terlihat*, Namun kamu tetap bisa menulis ulang:
|
||||||
|
|
||||||
|
| Prop | Description |
|
||||||
|
|---|---|
|
||||||
|
| width | lebar chart |
|
||||||
|
| height | tinggi chart |
|
||||||
|
| chart-id | id canvas |
|
||||||
|
| css-classes | String dengan kelas css mengelilingi div |
|
||||||
|
| styles | Objek dengan style css mengelilingi div |
|
||||||
|
|
||||||
|
## Contoh
|
||||||
|
|
||||||
|
Berikut adalah beberapa contoh penggunaan
|
||||||
|
|
||||||
|
### Chart dengan props
|
||||||
|
|
||||||
|
Kamu dapat membuat props data dan opsi untuk melewatkan data pada chart.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// LineChart.js
|
||||||
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
props: ['data', 'options'],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.data, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Setelah kamu menambahkannya kamu dapat menggunakannya seperti biasa:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<line-chart :data="{your data object}" :options="{your options}"></line-chart>
|
||||||
|
```
|
||||||
|
|
||||||
|
Jika kamu ingin mengatur tinggi dan lebar:
|
||||||
|
|
||||||
|
```html
|
||||||
|
<line-chart
|
||||||
|
:data="{your data object}"
|
||||||
|
:options="{responsive: false, maintainAspectRatio: false}"
|
||||||
|
:width="400"
|
||||||
|
:height="200"
|
||||||
|
>
|
||||||
|
</line-chart>
|
||||||
|
```
|
||||||
|
|
||||||
|
<p class="warning">
|
||||||
|
Perlu diingat, kamu perlu untuk mengatur `responsive: false` agaar dapat mengatur `width` dan `height`.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
### Chart dengan data lokal
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import {Bar} from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Bar,
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
datacollection: {
|
||||||
|
labels: ['January', 'February'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'Data One',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [40, 20]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Reusable Komponen
|
||||||
|
|
||||||
|
Jika kamu ingin agar komponen chart reusable, cara paling baik adalah dengan menambahkan sebuah wrapper. Dengan cara ini komponen chart hanya bertanggung jawab dalam representasi data dan wrapper komponen bertanggung jawab dengan logika didalamnya. Banyak kasus-kasus yang berbeda dan juga berbeda jika kamu menjalankan Single Page Application atau mengintegrasikannya pada contoh laravel.
|
||||||
|
|
||||||
|
## Reactive Data
|
||||||
|
|
||||||
|
Chart.js tidak menyediakan live update jika kamu mengubah datasets. Akan tetapi `vue-chartjs` menyediakan 2 mixins untuk melakukannya.
|
||||||
|
|
||||||
|
- `reactiveProp`
|
||||||
|
- `reactiveData`
|
||||||
|
|
||||||
|
Kedua mixins tersebut sebenarnya sama. `reactiveProp` akan sering digunakan. `reactiveProp` meng-extend logika dari komponen chart dan secara otomatis membuat props `chartData` dan menambahkan `vue watch` dalam props ini. Pada saat data berubah, itu akan memanggil `update()` jika data memiliki datasets atau `renderChart()` jika datasets telah ada sebelumnya.
|
||||||
|
|
||||||
|
`reactiveData` secara sederhana membuat variabel lokal chartData dimana itu bukan sebuah props! dan watcher. Hal ini bisa berguna, jika kamu membutuhkan chart tertentu dan melakukan akses API didalam komponen chart.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
chartData: null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Contoh
|
||||||
|
|
||||||
|
**LineChart.js**
|
||||||
|
```javascript
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
mixins: [reactiveProp],
|
||||||
|
props: ['options'],
|
||||||
|
mounted () {
|
||||||
|
// this.chartData is created in the mixin.
|
||||||
|
// If you want to pass options please create a local options object
|
||||||
|
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">
|
||||||
|
⚠ Perhatian: jika kamu memutasi data didalam komponen parent dan melewatkannya pada child komponen chart perlu diingat batasan javascript.
|
||||||
|
Info lebih lanjut [issue#44](https://github.com/apertureless/vue-chartjs/issues/44)
|
||||||
|
</p>
|
||||||
|
|
||||||
|
### Batasan
|
||||||
|
<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>
|
||||||
|
|
||||||
|
## Objek Chart.js
|
||||||
|
|
||||||
|
Suatu ketika kamu membutuhkan kontrol chart.js. Kamu dapat mengaksesnya dengan `this.$data._chart`
|
||||||
|
|
||||||
|
## Inline plugins
|
||||||
|
|
||||||
|
Di Chart.js kamu dapat mendefinisikan plugin global dan inline. Plugin global bekerja tanpa masalah dengan `vue-chartjs` seperti yang dijelaskan pada [chart.js docs](http://www.chartjs.org/docs/latest/developers/plugins.html)
|
||||||
|
|
||||||
|
If you want to add inline plugins, `vue-chartjs` exposes a helper method called `addPlugin()`
|
||||||
|
You should call `addPlugin()` before the `renderChart()` method.
|
||||||
|
Jika kamu ingin menambahkan plugin inline, `vue-chartjs` menyediakan method helper `addPlugin()` kamu harus memanggil `addPlugin()` sebelum method `renderChart()`.
|
||||||
|
|
||||||
|
### Contoh
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
mounted () {
|
||||||
|
this.addPlugin({
|
||||||
|
id: 'my-plugin',
|
||||||
|
beforeInit: function (chart) {
|
||||||
|
....
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Charts yang Tersedia
|
||||||
|
|
||||||
|
### Bar Chart
|
||||||
|
<p class="tip">
|
||||||
|
Terdapat dua versi bar chart. `{Bar}` dan `{HorizontalBar}`
|
||||||
|
</p>
|
||||||
|
|
||||||
|

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

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

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

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

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

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

|
||||||
|
|
||||||
|
### Scatter
|
||||||
|
|
||||||
|
This chart has a different data structure then the others. Right now the reactive Mixins are not working for this chart type.
|
||||||
|
Chart ini memiliki struktur data yang berbeda dengan yang lainnya. Untuk sekarang reactive mixins tidak dapat bekerja pada tipe chart ini.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
|
## Penjelasan Build
|
||||||
|
Terdapat tiga jenis titik entri. Tergantung setup mana yang kamu gunakan. Dependensi-dependensi telah di-bundle atau require sebagai peerDependency.
|
||||||
|
|
||||||
|
- Browser
|
||||||
|
- Browserify / Webpack 1
|
||||||
|
- Webpack 2
|
||||||
|
|
||||||
|
|
||||||
|
| Build | Chart.js | Vue.js |
|
||||||
|
|---|---|---|
|
||||||
|
| vue-chartjs.full.js | Bundled | Bundled |
|
||||||
|
| vue-chartjs.full.min.js | Bundled | Bundled |
|
||||||
|
| vue-chartjs.js | peerDependency | peerDependency |
|
||||||
|
| vue-chartjs.min.js | peerDependency | peerDependency |
|
||||||
|
| es/index* | peerDependency | peerDependency |
|
||||||
|
|
||||||
|
### Browser
|
||||||
|
Kamu dapat menggunakan `vue-chartjs` secara langsung didalam browser tanpa setup build. Seperti berikut [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). Dalam kasus ini, mohon gunakan `vue-chartjs.full.min.js` yang telah di-minify. Didalamnya terdapat Vue.js dan Chart.js. Dan bundel modul UMD. Jadi kamu hanya membutuhkan satu file saja.
|
||||||
|
|
||||||
|
|
||||||
|
### Browserify / Webpack 1
|
||||||
|
|
||||||
|
Jika kamu menggunakan GUlp, Browserify atau Webpack 1 entri yang digunakan adalah `vue-chartjs.js` dimana telah di__transpile__ dan di__bundle__ UMD Module.
|
||||||
|
|
||||||
|
Bagaimanapun juga Vue.js dan Chart.js adalah `peerDependencies` jadi kamu harus meng-instalnya secara terpisah. Jika kamu telah memiliki `Vue.js` kamu dapat menggunakan versi Vue.js dan Chart.js yang terdapat di-package ini.
|
||||||
|
|
||||||
|
### Webpack 2
|
||||||
|
Jika kamu menggunakan Webpack 2 secara otomatis akan menggunakan titik entri `jsnext:main` / `module`. Di `es/index.js`
|
||||||
|
Di__transpile__ es sumber dari versi ini. Dan tidak di__bundle__ pada modul. Sehingga tree shaking akan bekerja. Sama seperti versi bundle, `Vue.js` dan `Chart.js` adalah `peerDependencies` dan butuh untuk diinstal.
|
||||||
|
|
||||||
|
## Sumber-sumber
|
||||||
|
|
||||||
|
Kamu dapat menemukan sumber-sumber seperti tutrial bagaimana cara untuk menggunakan `vue-chartjs`
|
||||||
|
|
||||||
|
- [Using vue-chartjs with WordPress](https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f)
|
||||||
|
- [Create stunning Charts with Vue and Chart.js](https://hackernoon.com/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a)
|
||||||
|
- [Let’s Build a Web App with Vue, Chart.js and an API Part I](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44)
|
||||||
|
- [Let’s Build a Web App with Vue, Chart.js and an API Part II](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf)
|
||||||
|
- [Build a realtime chart with VueJS and Pusher](https://blog.pusher.com/build-realtime-chart-with-vuejs-pusher/)
|
||||||
@@ -32,12 +32,13 @@ BaseChartをインポートしてextendします。
|
|||||||
// CommitChart.js
|
// CommitChart.js
|
||||||
import { Bar } from 'vue-chartjs'
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mounted () {
|
mounted () {
|
||||||
// Overwriting base render method with actual data.
|
// Overwriting base render method with actual data.
|
||||||
this.renderChart(data, options)
|
this.renderChart(data, options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
renderChart()メソッドに2つの引数を渡すことができます:
|
renderChart()メソッドに2つの引数を渡すことができます:
|
||||||
@@ -86,12 +87,13 @@ dataとoptionsプロパティを作成して、チャートにデータを渡す
|
|||||||
// LineChart.js
|
// LineChart.js
|
||||||
import { Line } from 'vue-chartjs'
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
props: ['data', 'options'],
|
props: ['data', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.data, this.options)
|
this.renderChart(this.data, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
コンポーネントに追加して、使用することができます。
|
コンポーネントに追加して、使用することができます。
|
||||||
@@ -121,7 +123,8 @@ export default Line.extend({
|
|||||||
```javascript
|
```javascript
|
||||||
import {Bar} from 'vue-chartjs'
|
import {Bar} from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
datacollection: {
|
datacollection: {
|
||||||
@@ -139,7 +142,7 @@ export default Bar.extend({
|
|||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### コンポーネントの再利用
|
### コンポーネントの再利用
|
||||||
@@ -174,14 +177,15 @@ data () {
|
|||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
const { reactiveProp } = mixins
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [reactiveProp],
|
mixins: [reactiveProp],
|
||||||
props: ['options'],
|
props: ['options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
// this.chartData is created in the mixin
|
// this.chartData is created in the mixin
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**RandomChart.vue**
|
**RandomChart.vue**
|
||||||
@@ -255,7 +259,7 @@ export default Line.extend({
|
|||||||
|
|
||||||
## Chart.js オブジェクト
|
## 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
|
// CommitChart.js
|
||||||
import { Bar } from 'vue-chartjs'
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mounted () {
|
mounted () {
|
||||||
// Overwriting base render method with actual data.
|
// Overwriting base render method with actual data.
|
||||||
this.renderChart({
|
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.
|
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
|
// MonthlyIncome.js
|
||||||
import { Line } from 'vue-chartjs'
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
props: ["data", "options"],
|
props: ["data", "options"],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.data, this.options)
|
this.renderChart(this.data, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Use isso no seu componente vue
|
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
|
// MonthlyIncome.js
|
||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [mixins.reactiveProp],
|
mixins: [mixins.reactiveProp],
|
||||||
props: ["chartData", "options"],
|
props: ["chartData", "options"],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -181,26 +184,28 @@ Algumas maneiras de importá-los:
|
|||||||
// Load complete module with all charts
|
// Load complete module with all charts
|
||||||
import VueCharts from 'vue-chartjs'
|
import VueCharts from 'vue-chartjs'
|
||||||
|
|
||||||
export default VueCharts.Line.extend({
|
export default {
|
||||||
|
extends: VueCharts.Line,
|
||||||
mixins: [VueCharts.mixins.reactiveProp],
|
mixins: [VueCharts.mixins.reactiveProp],
|
||||||
props: ["chartData", "options"],
|
props: ["chartData", "options"],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
// Load speperate modules
|
// Load speperate modules
|
||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [mixins.reactiveProp],
|
mixins: [mixins.reactiveProp],
|
||||||
props: ["chartData", "options"],
|
props: ["chartData", "options"],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
@@ -208,13 +213,14 @@ export default Line.extend({
|
|||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
const { reactiveProp } = mixins
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [reactiveProp],
|
mixins: [reactiveProp],
|
||||||
props: ["chartData", "options"],
|
props: ["chartData", "options"],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Gráficos disponíveis
|
## Gráficos disponíveis
|
||||||
|
|||||||
300
docs/ru/README.md
Normal file
@@ -0,0 +1,300 @@
|
|||||||
|
---
|
||||||
|
search: ru
|
||||||
|
---
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<img width="256" heigth="256" src="../../assets/vue-chartjs.png" alt="vue-chartjs logo">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
[](https://badge.fury.io/js/vue-chartjs)
|
||||||
|
[](https://codecov.io/gh/apertureless/vue-chartjs)
|
||||||
|
[](https://travis-ci.org/apertureless/vue-chartjs)
|
||||||
|
[](http://packagequality.com/#?package=vue-chartjs)
|
||||||
|
[](https://www.npmjs.com/package/vue-chartjs)
|
||||||
|
[](https://gitter.im/vue-chartjs/Lobby)
|
||||||
|
[](https://github.com/apertureless/vue-chartjs/blob/master/LICENSE.txt)
|
||||||
|
[](https://cdnjs.com/libraries/vue-chartjs)
|
||||||
|
|
||||||
|
# vue-chartjs
|
||||||
|
|
||||||
|
**vue-chartjs** это обертка для [Chart.js](https://github.com/chartjs/Chart.js) в vue. Вы можете с легкостью создавать многоразовые компоненты диаграмм.
|
||||||
|
|
||||||
|
## Демо & Документация
|
||||||
|
|
||||||
|
- 📺 [Demo](http://demo.vue-chartjs.org/)
|
||||||
|
- 📖 [Docs](http://www.vue-chartjs.org/)
|
||||||
|
|
||||||
|
### Совместимость
|
||||||
|
|
||||||
|
- v1 later `@legacy`
|
||||||
|
- Vue.js 1.x
|
||||||
|
- v2 later
|
||||||
|
- Vue.js 2.x
|
||||||
|
|
||||||
|
После финального выпуска vue.js 2, вы получите v2 по умолчанию, если установите vue-chartjs через npm.
|
||||||
|
Больше нет необходимости в @next теге. Если вы нуждаетесь в v1, вам необходимо указать версию или использовать legacy тег.
|
||||||
|
Если вы ищите v1, проверьте эту [ветку](https://github.com/apertureless/vue-chartjs/tree/release/1.x).
|
||||||
|
|
||||||
|
## Установка
|
||||||
|
|
||||||
|
Просто выполните `yarn add vue-chartjs chart.js`
|
||||||
|
|
||||||
|
В случае если вы хотите использовать библиотеку прямо в браузере, добавьте
|
||||||
|
|
||||||
|
```html
|
||||||
|
<script src="https://unpkg.com/vue-chartjs@2.6.0/dist/vue-chartjs.full.min.js"></script>
|
||||||
|
```
|
||||||
|
в ваши скрипты. Смотрите пример на [Codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010)
|
||||||
|
|
||||||
|
## Описание различий сборок
|
||||||
|
|
||||||
|
Существует три различные точки входа. Это зависит от того, какая сборка стоит у вас. Зависимости собираются или подключаются как peerDependency.
|
||||||
|
|
||||||
|
- Browser
|
||||||
|
- Browserify / Webpack 1
|
||||||
|
- Webpack 2
|
||||||
|
|
||||||
|
|
||||||
|
| Build | Chart.js | Vue.js |
|
||||||
|
|---|---|---|
|
||||||
|
| vue-chartjs.full.js | Bundled | Bundled |
|
||||||
|
| vue-chartjs.full.min.js | Bundled | Bundled |
|
||||||
|
| vue-chartjs.js | peerDependency | peerDependency |
|
||||||
|
| vue-chartjs.min.js | peerDependency | peerDependency |
|
||||||
|
| es/index* | peerDependency | peerDependency |
|
||||||
|
|
||||||
|
### Браузер
|
||||||
|
Вы можете использовать `vue-chartjs` прямо в браузере без установки каких-либо сборок. Пример на [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). В этом случае, пожалуйста, используйте `vue-chartjs.full.min.js`. Это минифицированная версия библиотеки, содержащая Vue.js и Chart.js в себе, с возможностью подключения при помощи UMD Module. Таким образом, вам необходим лишь один файл.
|
||||||
|
|
||||||
|
|
||||||
|
### Browserify / Webpack 1
|
||||||
|
|
||||||
|
Если вы используете Gulp, Browserify или Webpack 1, входная точка находится в `vue-chartjs.js`. Она __транслируется__ и __собирается__ при помощи UMD Module.
|
||||||
|
|
||||||
|
Однако Vue.js и Chart.js являются `peerDependencies`, поэтому вы можете устанавливать их отдельно. В большинстве проектов вы в любом случае будете иметь установленный `Vue.js`. В этом случае, вы можете иметь различные версии Vue.js и Chart.js.
|
||||||
|
|
||||||
|
### Webpack 2
|
||||||
|
Если вы используете Webpack 2, он будет автоматически использовать `jsnext:main` / `module` в качестве входной точки, которая расположена в `es/index.js`.
|
||||||
|
Это транслированная es версия кода, которая не __собирается__ в модуль. Таким образом, three shaking будет работать.
|
||||||
|
Как и в собранной версии, `Vue.js` и `Chart.js` являются `peerDependencies` и не нуждаются в установке.
|
||||||
|
|
||||||
|
|
||||||
|
## Как использовать
|
||||||
|
|
||||||
|
Вам необходимо импортировать базовый класс диаграммы и унаследовать его. Это даст гораздо большую гибкость при работе с различными данными. Вы можете передать данные через props или vue-resource.
|
||||||
|
|
||||||
|
Вы можете импортировать весь проект или каждый модуль по отдельности.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import VueCharts from 'vue-chartjs'
|
||||||
|
import { Bar, Line } from 'vue-chartjs'
|
||||||
|
```
|
||||||
|
|
||||||
|
Просто создайте ваш собственный компонент.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// CommitChart.js
|
||||||
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Bar,
|
||||||
|
mounted () {
|
||||||
|
// Переопределение базового рендер метода с реальными данными.
|
||||||
|
this.renderChart({
|
||||||
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: 'GitHub Commits',
|
||||||
|
backgroundColor: '#f87979',
|
||||||
|
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Затем просто импортируйте и используйте ваши собственные расширенные компоненты как обычные vue компоненты.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import CommitChart from 'path/to/component/CommitChart'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Другой пример с options
|
||||||
|
|
||||||
|
Вы можете переопределить стандартные опции графика. Просто передайте объект с опциями в качестве второго параметра в рендер метод.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// MonthlyIncome.js
|
||||||
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
props: ['data', 'options'],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.data, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Используйте это в вашем vue приложении
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import MonthlyIncome from 'path/to/component/MonthlyIncome'
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<monthly-income :data={....} />
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
components: { MonthlyIncome },
|
||||||
|
....
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
```
|
||||||
|
|
||||||
|
## Реактивность
|
||||||
|
|
||||||
|
Chart.js не обновляет и не перерисовывает диаграмму при передаче новых данных.
|
||||||
|
Впрочем, вы можете реализовать это самостоятельно или использовать один из двух подключенных миксинов:
|
||||||
|
|
||||||
|
- `reactiveProp`
|
||||||
|
- `reactiveData`
|
||||||
|
|
||||||
|
Оба включены в `mixins` модуль.
|
||||||
|
|
||||||
|
Миксины автоматически создают `chartData` в виде prop или data. И добавляют watcher. Если данные были измененны, график обновится.
|
||||||
|
Но помните про ограничения vue и javascript на изменение массивов и объектов. Больше информации можно получить [здесь](http://vue-chartjs.org/#/home?id=reactive-data)
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// MonthlyIncome.js
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
mixins: [mixins.reactiveProp],
|
||||||
|
props: ['chartData', 'options'],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
### Mixins модуль
|
||||||
|
Модуль `mixins` включен в `VueCharts`, а также доступен в виде отдельного модуля.
|
||||||
|
Несколько способов импортировать их:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Load complete module with all charts
|
||||||
|
import VueCharts from 'vue-chartjs'
|
||||||
|
|
||||||
|
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 {
|
||||||
|
extends: Line,
|
||||||
|
mixins: [mixins.reactiveProp],
|
||||||
|
props: ['chartData', 'options'],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// Load speperate modules with destructure assign
|
||||||
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
|
export default {
|
||||||
|
extends: Line,
|
||||||
|
mixins: [reactiveProp],
|
||||||
|
props: ['chartData', 'options'],
|
||||||
|
mounted () {
|
||||||
|
this.renderChart(this.chartData, this.options)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Доступные диаграммы
|
||||||
|
|
||||||
|
### Bar Chart
|
||||||
|
|
||||||
|

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

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

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

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

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

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

|
||||||
|
|
||||||
|
### Scatter
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
## Настройка сборки
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
# инициализация зависимостей
|
||||||
|
npm install
|
||||||
|
|
||||||
|
# сборка с горячей заменой на localhost:8080
|
||||||
|
npm run dev
|
||||||
|
|
||||||
|
# сборка для production с минификацией
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
# запуск unit тестов
|
||||||
|
npm run unit
|
||||||
|
|
||||||
|
# запуск e2e тестов
|
||||||
|
npm run e2e
|
||||||
|
|
||||||
|
# запуск всех тестов
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
Для получения детальных объяснений того, как это работает, перейдите в [руководство](http://vuejs-templates.github.io/webpack/) и [документацию для vue-loader](http://vuejs.github.io/vue-loader).
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
1. Fork it ( https://github.com/apertureless/vue-chartjs/fork )
|
||||||
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
||||||
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
||||||
|
4. Push to the branch (`git push origin my-new-feature`)
|
||||||
|
5. Create a new Pull Request
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This software is distributed under [MIT license](LICENSE.txt).
|
||||||
@@ -31,12 +31,13 @@ search: zh-cn
|
|||||||
// CommitChart.js
|
// CommitChart.js
|
||||||
import { Bar } from 'vue-chartjs'
|
import { Bar } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mounted () {
|
mounted () {
|
||||||
// Overwriting base render method with actual data.
|
// Overwriting base render method with actual data.
|
||||||
this.renderChart(data, options)
|
this.renderChart(data, options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
你可以给 `renderChart()` 方法传递两个参数:
|
你可以给 `renderChart()` 方法传递两个参数:
|
||||||
@@ -86,12 +87,13 @@ export default Bar.extend({
|
|||||||
// LineChart.js
|
// LineChart.js
|
||||||
import { Line } from 'vue-chartjs'
|
import { Line } from 'vue-chartjs'
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
props: ['data', 'options'],
|
props: ['data', 'options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.data, this.options)
|
this.renderChart(this.data, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
然后你可以把它作为组件使用。
|
然后你可以把它作为组件使用。
|
||||||
@@ -121,7 +123,8 @@ export default Line.extend({
|
|||||||
```javascript
|
```javascript
|
||||||
import {Bar} from 'vue-chartjs'
|
import {Bar} from 'vue-chartjs'
|
||||||
|
|
||||||
export default Bar.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
datacollection: {
|
datacollection: {
|
||||||
@@ -139,7 +142,7 @@ export default Bar.extend({
|
|||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
this.renderChart(this.datacollection, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### 可复用的组件
|
### 可复用的组件
|
||||||
@@ -172,14 +175,15 @@ data () {
|
|||||||
import { Line, mixins } from 'vue-chartjs'
|
import { Line, mixins } from 'vue-chartjs'
|
||||||
const { reactiveProp } = mixins
|
const { reactiveProp } = mixins
|
||||||
|
|
||||||
export default Line.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mixins: [reactiveProp],
|
mixins: [reactiveProp],
|
||||||
props: ['options'],
|
props: ['options'],
|
||||||
mounted () {
|
mounted () {
|
||||||
// this.chartData is created in the mixin
|
// this.chartData is created in the mixin
|
||||||
this.renderChart(this.chartData, this.options)
|
this.renderChart(this.chartData, this.options)
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**RandomChart.vue**
|
**RandomChart.vue**
|
||||||
@@ -253,7 +257,7 @@ export default Line.extend({
|
|||||||
|
|
||||||
## Chart.js 对象
|
## Chart.js 对象
|
||||||
|
|
||||||
有时你需要更多的调整 chart.js。你可以访问 `this._chart` 实例。
|
有时你需要更多的调整 chart.js。你可以访问 `this.$data._chart` 实例。
|
||||||
|
|
||||||
## 内联插件
|
## 内联插件
|
||||||
|
|
||||||
|
|||||||
25
package.json
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "vue-chartjs",
|
"name": "vue-chartjs",
|
||||||
"version": "2.8.0",
|
"version": "3.0.0",
|
||||||
"description": "vue.js wrapper for chart.js",
|
"description": "Vue.js wrapper for chart.js for creating beautiful charts.",
|
||||||
"author": "Jakub Juszczak <jakub@posteo.de>",
|
"author": "Jakub Juszczak <jakub@posteo.de>",
|
||||||
"homepage": "http://vue-chartjs.org",
|
"homepage": "http://vue-chartjs.org",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
@@ -57,22 +57,23 @@
|
|||||||
"prepublish": "yarn run lint && yarn run test && yarn run build"
|
"prepublish": "yarn run lint && yarn run test && yarn run build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.4"
|
"lodash.merge": "^4.6.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
"chart.js": "^2.6.0",
|
"chart.js": "2.7.0",
|
||||||
"vue": "^2.4.2"
|
"vue": "2.5.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-cli": "^6.24.1",
|
"babel-cli": "^6.24.1",
|
||||||
"babel-core": "^6.25.0",
|
"babel-core": "^6.25.0",
|
||||||
"babel-loader": "^7.0.0",
|
"babel-loader": "6.4.1",
|
||||||
|
"babel-plugin-transform-object-assign": "^6.22.0",
|
||||||
"babel-plugin-transform-runtime": "^6.23.0",
|
"babel-plugin-transform-runtime": "^6.23.0",
|
||||||
"babel-preset-es2015": "^6.24.1",
|
"babel-preset-es2015": "^6.24.1",
|
||||||
"babel-preset-stage-2": "^6.24.1",
|
"babel-preset-stage-2": "^6.24.1",
|
||||||
"babel-runtime": "^6.23.0",
|
"babel-runtime": "^6.23.0",
|
||||||
"chai": "^3.5.0",
|
"chai": "^3.5.0",
|
||||||
"chart.js": "^2.6.0",
|
"chart.js": "2.7.0",
|
||||||
"chromedriver": "^2.28.0",
|
"chromedriver": "^2.28.0",
|
||||||
"connect-history-api-fallback": "^1.1.0",
|
"connect-history-api-fallback": "^1.1.0",
|
||||||
"cross-env": "^3.2.4",
|
"cross-env": "^3.2.4",
|
||||||
@@ -117,12 +118,12 @@
|
|||||||
"sinon": "^2.1.0",
|
"sinon": "^2.1.0",
|
||||||
"sinon-chai": "^2.9.0",
|
"sinon-chai": "^2.9.0",
|
||||||
"url-loader": "^0.5.8",
|
"url-loader": "^0.5.8",
|
||||||
"vue": "^2.4.2",
|
"vue": "2.5.2",
|
||||||
"vue-hot-reload-api": "^2.1.0",
|
"vue-hot-reload-api": "2.1.0",
|
||||||
"vue-html-loader": "^1.2.4",
|
"vue-html-loader": "^1.2.4",
|
||||||
"vue-loader": "^12.2.2",
|
"vue-loader": "12.2.2",
|
||||||
"vue-style-loader": "^3.0.1",
|
"vue-style-loader": "3.0.1",
|
||||||
"vue-template-compiler": "^2.4.2",
|
"vue-template-compiler": "2.5.2",
|
||||||
"webpack": "^1.13.2",
|
"webpack": "^1.13.2",
|
||||||
"webpack-dev-middleware": "^1.10.1",
|
"webpack-dev-middleware": "^1.10.1",
|
||||||
"webpack-hot-middleware": "^2.17.1",
|
"webpack-hot-middleware": "^2.17.1",
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -41,18 +40,12 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{
|
||||||
@@ -82,7 +75,7 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -93,8 +86,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{
|
||||||
@@ -85,7 +78,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'bubble',
|
type: 'bubble',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -96,8 +89,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
},
|
},
|
||||||
plugins: []
|
plugins: []
|
||||||
@@ -68,7 +61,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'doughnut',
|
type: 'doughnut',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -79,8 +72,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{
|
||||||
@@ -84,7 +77,7 @@ export default Vue.extend({
|
|||||||
},
|
},
|
||||||
renderChart (data, options, type) {
|
renderChart (data, options, type) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'horizontalBar',
|
type: 'horizontalBar',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -95,8 +88,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
scales: {
|
scales: {
|
||||||
yAxes: [{
|
yAxes: [{
|
||||||
@@ -83,7 +76,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'line',
|
type: 'line',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -94,8 +87,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
},
|
},
|
||||||
plugins: []
|
plugins: []
|
||||||
@@ -68,7 +61,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'pie',
|
type: 'pie',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -79,8 +72,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
},
|
},
|
||||||
plugins: []
|
plugins: []
|
||||||
@@ -68,7 +61,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'polarArea',
|
type: 'polarArea',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -79,8 +72,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
},
|
},
|
||||||
plugins: []
|
plugins: []
|
||||||
@@ -68,7 +61,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'radar',
|
type: 'radar',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -79,8 +72,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import Vue from 'vue'
|
|
||||||
import Chart from 'chart.js'
|
import Chart from 'chart.js'
|
||||||
import { mergeOptions } from '../helpers/options'
|
import { mergeOptions } from '../helpers/options'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default {
|
||||||
render: function (createElement) {
|
render: function (createElement) {
|
||||||
return createElement(
|
return createElement(
|
||||||
'div', {
|
'div', {
|
||||||
@@ -42,19 +41,13 @@ export default Vue.extend({
|
|||||||
default: ''
|
default: ''
|
||||||
},
|
},
|
||||||
styles: {
|
styles: {
|
||||||
type: Object,
|
type: Object
|
||||||
default () {
|
|
||||||
return {
|
|
||||||
width: '100%',
|
|
||||||
height: '200%',
|
|
||||||
position: 'relative'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
|
_chart: null,
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
scales: {
|
scales: {
|
||||||
xAxes: [{
|
xAxes: [{
|
||||||
@@ -74,7 +67,7 @@ export default Vue.extend({
|
|||||||
renderChart (data, options) {
|
renderChart (data, options) {
|
||||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||||
|
|
||||||
this._chart = new Chart(
|
this.$data._chart = new Chart(
|
||||||
this.$refs.canvas.getContext('2d'), {
|
this.$refs.canvas.getContext('2d'), {
|
||||||
type: 'scatter',
|
type: 'scatter',
|
||||||
data: data,
|
data: data,
|
||||||
@@ -85,8 +78,8 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
beforeDestroy () {
|
beforeDestroy () {
|
||||||
if (this._chart) {
|
if (this.$data._chart) {
|
||||||
this._chart.destroy()
|
this.$data._chart.destroy()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import BarChart from '../BaseCharts/Bar'
|
import Bar from '../BaseCharts/Bar'
|
||||||
|
|
||||||
export default BarChart.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||||
@@ -13,4 +14,4 @@ export default BarChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import BubbleChart from '../BaseCharts/Bubble'
|
import Bubble from '../BaseCharts/Bubble'
|
||||||
|
|
||||||
export default BubbleChart.extend({
|
export default {
|
||||||
|
extends: Bubble,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
datasets: [
|
datasets: [
|
||||||
@@ -49,4 +50,4 @@ export default BubbleChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import DoughnutChart from '../BaseCharts/Doughnut'
|
import Doughnut from '../BaseCharts/Doughnut'
|
||||||
|
|
||||||
export default DoughnutChart.extend({
|
export default {
|
||||||
|
extends: Doughnut,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
||||||
@@ -17,4 +18,4 @@ export default DoughnutChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import HorizontalBarChart from '../BaseCharts/HorizontalBar'
|
import HorizontalBar from '../BaseCharts/HorizontalBar'
|
||||||
|
|
||||||
export default HorizontalBarChart.extend({
|
export default {
|
||||||
|
extends: HorizontalBar,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||||
@@ -13,4 +14,4 @@ export default HorizontalBarChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import LineChart from '../BaseCharts/Line'
|
import Line from '../BaseCharts/Line'
|
||||||
|
|
||||||
export default LineChart.extend({
|
export default {
|
||||||
|
extends: Line,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
labels: ['January', 'February', 'March', 'April', 'May', 'June', 'July'],
|
||||||
@@ -13,4 +14,4 @@ export default LineChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import PieChart from '../BaseCharts/Pie'
|
import Pie from '../BaseCharts/Pie'
|
||||||
|
|
||||||
export default PieChart.extend({
|
export default {
|
||||||
|
extends: Pie,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
labels: ['VueJs', 'EmberJs', 'ReactJs', 'AngularJs'],
|
||||||
@@ -17,4 +18,4 @@ export default PieChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import PolarAreaChart from '../BaseCharts/PolarArea'
|
import PolarArea from '../BaseCharts/PolarArea'
|
||||||
|
|
||||||
export default PolarAreaChart.extend({
|
export default {
|
||||||
|
extends: PolarArea,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
||||||
@@ -26,4 +27,4 @@ export default PolarAreaChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import RadarChart from '../BaseCharts/Radar'
|
import Radar from '../BaseCharts/Radar'
|
||||||
|
|
||||||
export default RadarChart.extend({
|
export default {
|
||||||
|
extends: Radar,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
labels: ['Eating', 'Drinking', 'Sleeping', 'Designing', 'Coding', 'Cycling', 'Running'],
|
||||||
@@ -28,4 +29,4 @@ export default RadarChart.extend({
|
|||||||
]
|
]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import BarChart from '../BaseCharts/Bar'
|
import Bar from '../BaseCharts/Bar'
|
||||||
import reactiveData from '../mixins/reactiveData'
|
import reactiveData from '../mixins/reactiveData'
|
||||||
|
|
||||||
export default BarChart.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mixins: [reactiveData],
|
mixins: [reactiveData],
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
@@ -38,4 +39,4 @@ export default BarChart.extend({
|
|||||||
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
|
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import BarChart from '../BaseCharts/Bar'
|
import Bar from '../BaseCharts/Bar'
|
||||||
import reactiveProp from '../mixins/reactiveProp'
|
import reactiveProp from '../mixins/reactiveProp'
|
||||||
|
|
||||||
export default BarChart.extend({
|
export default {
|
||||||
|
extends: Bar,
|
||||||
mixins: [reactiveProp],
|
mixins: [reactiveProp],
|
||||||
|
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart(this.chartData, {responsive: true, maintainAspectRatio: false})
|
this.renderChart(this.chartData, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import Scatter from '../BaseCharts/Scatter'
|
import Scatter from '../BaseCharts/Scatter'
|
||||||
|
|
||||||
export default Scatter.extend({
|
export default {
|
||||||
|
extends: Scatter,
|
||||||
mounted () {
|
mounted () {
|
||||||
this.renderChart({
|
this.renderChart({
|
||||||
datasets: [{
|
datasets: [{
|
||||||
@@ -49,4 +50,4 @@ export default Scatter.extend({
|
|||||||
}]
|
}]
|
||||||
}, {responsive: true, maintainAspectRatio: false})
|
}, {responsive: true, maintainAspectRatio: false})
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import merge from 'lodash/fp/merge'
|
import merge from 'lodash.merge'
|
||||||
|
|
||||||
export function mergeOptions (obj, src) {
|
export function mergeOptions (obj, src) {
|
||||||
return merge(obj, src)
|
return merge(obj, src)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module.exports = {
|
|||||||
'chartData': {
|
'chartData': {
|
||||||
handler (newData, oldData) {
|
handler (newData, oldData) {
|
||||||
if (oldData) {
|
if (oldData) {
|
||||||
let chart = this._chart
|
let chart = this.$data._chart
|
||||||
|
|
||||||
// Get new and old DataSet Labels
|
// Get new and old DataSet Labels
|
||||||
let newDatasetLabels = newData.datasets.map((dataset) => {
|
let newDatasetLabels = newData.datasets.map((dataset) => {
|
||||||
@@ -48,7 +48,15 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (newData.hasOwnProperty('labels')) {
|
||||||
chart.data.labels = newData.labels
|
chart.data.labels = newData.labels
|
||||||
|
}
|
||||||
|
if (newData.hasOwnProperty('xLabels')) {
|
||||||
|
chart.data.xLabels = newData.xLabels
|
||||||
|
}
|
||||||
|
if (newData.hasOwnProperty('yLabels')) {
|
||||||
|
chart.data.yLabels = newData.yLabels
|
||||||
|
}
|
||||||
chart.update()
|
chart.update()
|
||||||
} else {
|
} else {
|
||||||
chart.destroy()
|
chart.destroy()
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ module.exports = {
|
|||||||
'chartData': {
|
'chartData': {
|
||||||
handler (newData, oldData) {
|
handler (newData, oldData) {
|
||||||
if (oldData) {
|
if (oldData) {
|
||||||
let chart = this._chart
|
let chart = this.$data._chart
|
||||||
|
|
||||||
// Get new and old DataSet Labels
|
// Get new and old DataSet Labels
|
||||||
let newDatasetLabels = newData.datasets.map((dataset) => {
|
let newDatasetLabels = newData.datasets.map((dataset) => {
|
||||||
@@ -48,7 +48,15 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (newData.hasOwnProperty('labels')) {
|
||||||
chart.data.labels = newData.labels
|
chart.data.labels = newData.labels
|
||||||
|
}
|
||||||
|
if (newData.hasOwnProperty('xLabels')) {
|
||||||
|
chart.data.xLabels = newData.xLabels
|
||||||
|
}
|
||||||
|
if (newData.hasOwnProperty('yLabels')) {
|
||||||
|
chart.data.yLabels = newData.yLabels
|
||||||
|
}
|
||||||
chart.update()
|
chart.update()
|
||||||
} else {
|
} else {
|
||||||
chart.destroy()
|
chart.destroy()
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('BarChart', () => {
|
|||||||
components: { BarChart }
|
components: { BarChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.equal
|
expect(vm.$children[0].$data._chart.chart.ctx).to.equal
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('BubbleChart', () => {
|
|||||||
components: { BubbleChart }
|
components: { BubbleChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('DoughnutChart', () => {
|
|||||||
components: { DoughnutChart }
|
components: { DoughnutChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('HorizontalBarChart', () => {
|
|||||||
components: { HorizontalBarChart }
|
components: { HorizontalBarChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('LineChart', () => {
|
|||||||
components: { LineChart }
|
components: { LineChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ describe('PieChart', () => {
|
|||||||
components: { PieChart }
|
components: { PieChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('PolarChart', () => {
|
|||||||
components: { PolarChart }
|
components: { PolarChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -50,13 +50,13 @@ describe('RadarChart', () => {
|
|||||||
components: { RadarChart }
|
components: { RadarChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -51,13 +51,13 @@ describe('ScatterChart', () => {
|
|||||||
components: { ScatterChart }
|
components: { ScatterChart }
|
||||||
}).$mount(el)
|
}).$mount(el)
|
||||||
|
|
||||||
expect(vm.$children[0]._chart.chart.ctx).not.to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).not.to.be.null
|
||||||
|
|
||||||
vm.$destroy()
|
vm.$destroy()
|
||||||
|
|
||||||
vm.$nextTick(() => {
|
vm.$nextTick(() => {
|
||||||
vm.$forceUpdate()
|
vm.$forceUpdate()
|
||||||
expect(vm.$children[0]._chart.chart.ctx).to.be.null
|
expect(vm.$children[0].$data._chart.chart.ctx).to.be.null
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -15,16 +15,40 @@ describe('mergeOptions.js', () => {
|
|||||||
c: 'c'
|
c: 'c'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const an = {
|
||||||
|
a: {
|
||||||
|
a: 'a'
|
||||||
|
},
|
||||||
|
b: {
|
||||||
|
b: 'a'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const bn = {
|
||||||
|
a: {
|
||||||
|
a: 'a'
|
||||||
|
},
|
||||||
|
b: {
|
||||||
|
b: 'b'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it('should replace old a and b if a and b are new', () => {
|
it('should replace old a and b if a and b are new', () => {
|
||||||
let ab = mergeOptions(a, b)
|
const ab = mergeOptions(a, b)
|
||||||
expect(ab).to.have.property('a').and.to.equal('b')
|
expect(ab).to.have.property('a').and.to.equal('b')
|
||||||
expect(ab).to.have.property('b').and.to.equal('b')
|
expect(ab).to.have.property('b').and.to.equal('b')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('should add c if c is new', () => {
|
it('should add c if c is new', () => {
|
||||||
let ac = mergeOptions(a, c)
|
const ac = mergeOptions(a, c)
|
||||||
expect(ac).to.have.property('a').and.to.equal('a')
|
expect(ac).to.have.property('a').and.to.equal('b')
|
||||||
expect(ac).to.have.property('b').and.to.equal('a')
|
expect(ac).to.have.property('b').and.to.equal('b')
|
||||||
expect(ac).to.have.property('c').and.to.equal('c')
|
expect(ac).to.have.property('c').and.to.equal('c')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should replace old a and b if a and b are new in nested objects', () => {
|
||||||
|
const ab = mergeOptions(an, bn)
|
||||||
|
expect(ab).to.have.deep.property('a.a').and.to.equal('a')
|
||||||
|
expect(ab).to.have.deep.property('b.b').and.to.equal('b')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||