mirror of
https://github.com/KevinMidboe/vue-chartjs.git
synced 2025-10-29 18:00:20 +00:00
Compare commits
49 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d980e32116 | ||
|
|
6732907fc5 | ||
|
|
d2f23156cc | ||
|
|
4d02df581f | ||
|
|
1d6e375e05 | ||
|
|
c827562839 | ||
|
|
720d75b56b | ||
|
|
75925f0d5c | ||
|
|
ddb47ff63a | ||
|
|
2df29e1cf1 | ||
|
|
6f77de832e | ||
|
|
f94b320dfa | ||
|
|
4ec6fa4cae | ||
|
|
ecdb98c4c8 | ||
|
|
c21cf2f3ac | ||
|
|
ef9fbe472a | ||
|
|
06c3148897 | ||
|
|
e716482154 | ||
|
|
59cc74a00d | ||
|
|
a7194b990f | ||
|
|
45e543b636 | ||
|
|
ae93b96b9c | ||
|
|
b3faeb4f2b | ||
|
|
42f552a1f2 | ||
|
|
b847becdc7 | ||
|
|
64e0a60dbf | ||
|
|
1be5149bde | ||
|
|
7d256e6492 | ||
|
|
b8e7ce11de | ||
|
|
98961547f3 | ||
|
|
c11127e64f | ||
|
|
0f98800b92 | ||
|
|
8eefeeef86 | ||
|
|
d913e9c515 | ||
|
|
377ae5e27a | ||
|
|
9bcffae429 | ||
|
|
086fb1d4e9 | ||
|
|
f241613107 | ||
|
|
af373cf09d | ||
|
|
a7776f8407 | ||
|
|
776f3976ec | ||
|
|
3785e73b43 | ||
|
|
9bf6e6078d | ||
|
|
e62e8c81fb | ||
|
|
9f79fb581d | ||
|
|
45d500d401 | ||
|
|
9f02e95355 | ||
|
|
d80eace435 | ||
|
|
d9f95fd737 |
44
CHANGELOG.md
44
CHANGELOG.md
@@ -1,5 +1,49 @@
|
||||
# Change Log
|
||||
|
||||
## [v2.2.0](https://github.com/apertureless/vue-chartjs/tree/v2.2.0) (2016-10-24)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v2.1.1...v2.2.0)
|
||||
|
||||
**Closed issues:**
|
||||
|
||||
- question:syntax with vue-loader [\#12](https://github.com/apertureless/vue-chartjs/issues/12)
|
||||
- Rerender when data has changed [\#10](https://github.com/apertureless/vue-chartjs/issues/10)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- add horizontal bar parameter [\#14](https://github.com/apertureless/vue-chartjs/pull/14) ([wahaha2012](https://github.com/wahaha2012))
|
||||
- WIP Feature/reactive chart data \#11 [\#11](https://github.com/apertureless/vue-chartjs/pull/11) ([apertureless](https://github.com/apertureless))
|
||||
|
||||
## [v2.1.1](https://github.com/apertureless/vue-chartjs/tree/v2.1.1) (2016-10-02)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v.2.1.0...v2.1.1)
|
||||
|
||||
## [v.2.1.0](https://github.com/apertureless/vue-chartjs/tree/v.2.1.0) (2016-09-23)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/v1.1.3...v.2.1.0)
|
||||
|
||||
## [v1.1.3](https://github.com/apertureless/vue-chartjs/tree/v1.1.3) (2016-09-08)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.1.2...v1.1.3)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Add test [\#1](https://github.com/apertureless/vue-chartjs/issues/1)
|
||||
|
||||
**Fixed bugs:**
|
||||
|
||||
- Passing chart size \(width / height\) as prop doesnt resize the chart [\#8](https://github.com/apertureless/vue-chartjs/issues/8)
|
||||
|
||||
**Merged pull requests:**
|
||||
|
||||
- Added bubble chart type [\#9](https://github.com/apertureless/vue-chartjs/pull/9) ([jcalonso](https://github.com/jcalonso))
|
||||
|
||||
## [1.1.2](https://github.com/apertureless/vue-chartjs/tree/1.1.2) (2016-09-07)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.1.1...1.1.2)
|
||||
|
||||
**Implemented enhancements:**
|
||||
|
||||
- Change name of the render method to ensure compatiblity with Vue 2.0 [\#4](https://github.com/apertureless/vue-chartjs/issues/4)
|
||||
|
||||
## [1.1.1](https://github.com/apertureless/vue-chartjs/tree/1.1.1) (2016-08-23)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.1.0...1.1.1)
|
||||
|
||||
## [1.1.0](https://github.com/apertureless/vue-chartjs/tree/1.1.0) (2016-08-21)
|
||||
[Full Changelog](https://github.com/apertureless/vue-chartjs/compare/1.0.3...1.1.0)
|
||||
|
||||
|
||||
55
README.md
55
README.md
@@ -4,11 +4,20 @@
|
||||
|
||||
> VueJS wrapper for ChartJs
|
||||
|
||||
# 🚧 VUE 2.0 WIP ⚠
|
||||
### Compatibility
|
||||
|
||||
- v1 later
|
||||
- Vue.js 1.x
|
||||
- v2 later
|
||||
- Vue.js 2.x
|
||||
|
||||
After the final release of vue.js 2, you also get the v2 per default if you install vue-chartjs over npm.
|
||||
No need for the @next tag anymore. If you want the v1 you need to define the version.
|
||||
If you're looking for v1 check this [branch](https://github.com/apertureless/vue-chartjs/tree/release/1.1.3)
|
||||
|
||||
## Install
|
||||
|
||||
Simply run `npm install vue-chartjs@next`
|
||||
Simply run `npm install vue-chartjs`
|
||||
|
||||
## How to use
|
||||
|
||||
@@ -27,7 +36,7 @@ Just create your own component.
|
||||
// CommitChart.js
|
||||
import { Bar } from 'vue-chartjs'
|
||||
|
||||
export default BarChart.extend({
|
||||
export default Bar.extend({
|
||||
mounted () {
|
||||
// Overwriting base render method with actual data.
|
||||
this.renderChart({
|
||||
@@ -58,8 +67,8 @@ You can overwrite the default chart options. Just pass the options object as a s
|
||||
// MonthlyIncome.js
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
export default LineChart.extend({
|
||||
props: [data, options],
|
||||
export default Line.extend({
|
||||
props: ["data", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.data, this.options)
|
||||
}
|
||||
@@ -83,6 +92,30 @@ export default {
|
||||
</script>
|
||||
```
|
||||
|
||||
## Reactivity
|
||||
|
||||
Chart.js does not update or re-render the chart if new data is passed.
|
||||
However you can simply implement this by your own or use one of the two mixins which are included.
|
||||
|
||||
- `reactiveProp`
|
||||
- `reactiveData`
|
||||
|
||||
The mixins automatically create `chartData` as a prop or data. And add a watcher. If data has changed, the chart will update.
|
||||
|
||||
```javascript
|
||||
// MonthlyIncome.js
|
||||
import { Line, reactiveProp } from 'vue-chartjs'
|
||||
|
||||
export default Line.extend({
|
||||
mixins: [reactiveProp],
|
||||
props: ["chartData", "options"],
|
||||
mounted () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
})
|
||||
|
||||
```
|
||||
|
||||
## Available Charts
|
||||
|
||||
### Bar Chart
|
||||
@@ -109,17 +142,9 @@ export default {
|
||||
|
||||

|
||||
|
||||
## Todo
|
||||
|
||||
- [x] ~~Implement Bar Chart~~
|
||||
- [x] ~~Implement Line Chart~~
|
||||
- [x] ~~Implement Radar Chart~~
|
||||
- [x] ~~Implement Polar Area Chart~~
|
||||
- [x] ~~Implement Pie Chart~~
|
||||
- [x] ~~Implement Doughnut Chart~~
|
||||
- [x] ~~Make npm module~~
|
||||
- [ ] Add tests
|
||||
### Bubble
|
||||
|
||||

|
||||
|
||||
## Build Setup
|
||||
|
||||
|
||||
BIN
assets/bubble.png
Normal file
BIN
assets/bubble.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 82 KiB |
34
codecov.yml
Normal file
34
codecov.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
codecov:
|
||||
branch: master
|
||||
|
||||
coverage:
|
||||
precision: 2
|
||||
round: down
|
||||
range: "70...100"
|
||||
|
||||
status:
|
||||
project:
|
||||
default:
|
||||
target: auto
|
||||
threshold: null
|
||||
branches: null
|
||||
|
||||
patch:
|
||||
default:
|
||||
target: auto
|
||||
branches: null
|
||||
|
||||
changes:
|
||||
default:
|
||||
branches: null
|
||||
|
||||
ignore:
|
||||
- "tests/*"
|
||||
- "src/examples/*"
|
||||
- "src/mixins/*"
|
||||
|
||||
|
||||
comment:
|
||||
layout: "header, diff, changes, sunburst, uncovered, tree"
|
||||
branches: null
|
||||
behavior: default
|
||||
34
dist/vue-chartjs.js
vendored
34
dist/vue-chartjs.js
vendored
File diff suppressed because one or more lines are too long
2
dist/vue-chartjs.js.map
vendored
2
dist/vue-chartjs.js.map
vendored
File diff suppressed because one or more lines are too long
46
package.json
46
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "vue-chartjs",
|
||||
"version": "2.1.0",
|
||||
"version": "2.2.0",
|
||||
"description": "Vue wrapper for chart.js",
|
||||
"author": "Jakub Juszczak <jakub@nextindex.de>",
|
||||
"repository": {
|
||||
@@ -27,7 +27,7 @@
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.11.6",
|
||||
"chart.js": "^2.2.1",
|
||||
"vue": "^2.0.0-rc.1"
|
||||
"vue": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-core": "^6.10.4",
|
||||
@@ -38,41 +38,43 @@
|
||||
"chai": "^3.5.0",
|
||||
"chromedriver": "^2.21.2",
|
||||
"connect-history-api-fallback": "^1.1.0",
|
||||
"cross-spawn": "^2.1.5",
|
||||
"css-loader": "^0.23.0",
|
||||
"eslint": "^2.10.2",
|
||||
"eslint-config-standard": "^5.1.0",
|
||||
"cross-spawn": "^4.0.2",
|
||||
"css-loader": "^0.25.0",
|
||||
"eslint": "^3.7.1",
|
||||
"eslint-config-standard": "^6.2.0",
|
||||
"eslint-friendly-formatter": "^2.0.5",
|
||||
"eslint-loader": "^1.3.0",
|
||||
"eslint-plugin-html": "^1.3.0",
|
||||
"eslint-plugin-promise": "^1.0.8",
|
||||
"eslint-plugin-standard": "^1.3.2",
|
||||
"eslint-plugin-promise": "^2.0.1",
|
||||
"eslint-plugin-standard": "^2.0.1",
|
||||
"eventsource-polyfill": "^0.9.6",
|
||||
"express": "^4.13.3",
|
||||
"extract-text-webpack-plugin": "^1.0.1",
|
||||
"file-loader": "^0.8.4",
|
||||
"file-loader": "^0.9.0",
|
||||
"function-bind": "^1.0.2",
|
||||
"html-webpack-plugin": "^2.8.1",
|
||||
"http-proxy-middleware": "^0.12.0",
|
||||
"http-proxy-middleware": "^0.17.2",
|
||||
"inject-loader": "^2.0.1",
|
||||
"isparta-loader": "^2.0.0",
|
||||
"jasmine-core": "^2.5.2",
|
||||
"json-loader": "^0.5.4",
|
||||
"karma": "^0.13.15",
|
||||
"karma-coverage": "^0.5.5",
|
||||
"karma-mocha": "^0.2.2",
|
||||
"karma": "^1.3.0",
|
||||
"karma-coverage": "^1.1.1",
|
||||
"karma-jasmine": "^1.0.2",
|
||||
"karma-mocha": "^1.2.0",
|
||||
"karma-phantomjs-launcher": "^1.0.0",
|
||||
"karma-sinon-chai": "^1.2.0",
|
||||
"karma-sourcemap-loader": "^0.3.7",
|
||||
"karma-spec-reporter": "0.0.24",
|
||||
"karma-spec-reporter": "0.0.26",
|
||||
"karma-webpack": "^1.7.0",
|
||||
"lodash": "^4.15.0",
|
||||
"lodash": "^4.16.3",
|
||||
"lolex": "^1.4.0",
|
||||
"mocha": "^2.4.5",
|
||||
"nightwatch": "^0.8.18",
|
||||
"ora": "^0.2.0",
|
||||
"phantomjs-prebuilt": "^2.1.3",
|
||||
"selenium-server": "2.53.0",
|
||||
"shelljs": "^0.6.0",
|
||||
"mocha": "^3.1.0",
|
||||
"nightwatch": "^0.9.8",
|
||||
"ora": "^0.3.0",
|
||||
"phantomjs-prebuilt": "^2.1.13",
|
||||
"selenium-server": "^2.53.1",
|
||||
"shelljs": "^0.7.4",
|
||||
"sinon": "^1.17.3",
|
||||
"sinon-chai": "^2.8.0",
|
||||
"url-loader": "^0.5.7",
|
||||
@@ -83,6 +85,6 @@
|
||||
"webpack": "^1.13.2",
|
||||
"webpack-dev-middleware": "^1.4.0",
|
||||
"webpack-hot-middleware": "^2.6.0",
|
||||
"webpack-merge": "^0.8.3"
|
||||
"webpack-merge": "^0.14.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,12 @@ export default Vue.extend({
|
||||
},
|
||||
|
||||
methods: {
|
||||
renderChart (data, options) {
|
||||
renderChart (data, options, type) {
|
||||
let chartOptions = mergeOptions(this.defaultOptions, options)
|
||||
|
||||
this._chart = new Chart(
|
||||
this.$refs.canvas.getContext('2d'), {
|
||||
type: 'bar',
|
||||
type: type || 'bar',
|
||||
data: data,
|
||||
options: chartOptions
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<template>
|
||||
<div class="container">
|
||||
<bar-example></bar-example>
|
||||
<reactive-example></reactive-example>
|
||||
<line-example></line-example>
|
||||
<doughnut-example></doughnut-example>
|
||||
<pie-example></pie-example>
|
||||
@@ -18,9 +19,21 @@
|
||||
import RadarExample from './RadarExample'
|
||||
import PolarAreaExample from './PolarAreaExample'
|
||||
import BubbleExample from './BubbleExample'
|
||||
import ReactiveExample from './ReactiveExample'
|
||||
import ReactivePropExample from './ReactivePropExample'
|
||||
|
||||
export default {
|
||||
components: { BarExample, LineExample, DoughnutExample, PieExample, RadarExample, PolarAreaExample, BubbleExample }
|
||||
components: {
|
||||
BarExample,
|
||||
LineExample,
|
||||
DoughnutExample,
|
||||
PieExample,
|
||||
RadarExample,
|
||||
PolarAreaExample,
|
||||
BubbleExample,
|
||||
ReactiveExample,
|
||||
ReactivePropExample
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -11,6 +11,6 @@ export default BarChart.extend({
|
||||
data: [40, 20, 12, 39, 10, 40, 39, 80, 40, 20, 12, 11]
|
||||
}
|
||||
]
|
||||
})
|
||||
}, {responsive: true, maintainAspectRatio: false})
|
||||
}
|
||||
})
|
||||
|
||||
41
src/examples/ReactiveExample.js
Normal file
41
src/examples/ReactiveExample.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import BarChart from '../BaseCharts/Bar'
|
||||
import reactiveData from '../mixins/reactiveData'
|
||||
|
||||
export default BarChart.extend({
|
||||
mixins: [reactiveData],
|
||||
data () {
|
||||
return {
|
||||
chartData: ''
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.fillData()
|
||||
},
|
||||
|
||||
mounted () {
|
||||
this.renderChart(this.chartData)
|
||||
|
||||
setInterval(() => {
|
||||
this.fillData()
|
||||
}, 5000)
|
||||
},
|
||||
|
||||
methods: {
|
||||
fillData () {
|
||||
this.chartData = {
|
||||
labels: ['January' + this.getRandomInt(), 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Data One',
|
||||
backgroundColor: '#f87979',
|
||||
data: [this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt(), this.getRandomInt()]
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
|
||||
getRandomInt () {
|
||||
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
|
||||
}
|
||||
}
|
||||
})
|
||||
10
src/examples/ReactivePropExample.js
Normal file
10
src/examples/ReactivePropExample.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import BarChart from '../BaseCharts/Bar'
|
||||
import reactiveData from '../mixins/reactiveProp'
|
||||
|
||||
export default BarChart.extend({
|
||||
mixins: [reactiveData],
|
||||
|
||||
mounted () {
|
||||
this.renderChart(this.chartData)
|
||||
}
|
||||
})
|
||||
@@ -5,6 +5,8 @@ import Pie from './BaseCharts/Pie'
|
||||
import PolarArea from './BaseCharts/PolarArea'
|
||||
import Radar from './BaseCharts/Radar'
|
||||
import Bubble from './BaseCharts/Bubble'
|
||||
import reactiveProp from './mixins/reactiveProp'
|
||||
import reactiveData from './mixins/reactiveData'
|
||||
|
||||
const VueCharts = {
|
||||
Bar,
|
||||
@@ -13,7 +15,9 @@ const VueCharts = {
|
||||
Pie,
|
||||
PolarArea,
|
||||
Radar,
|
||||
Bubble
|
||||
Bubble,
|
||||
reactiveProp,
|
||||
reactiveData
|
||||
}
|
||||
|
||||
module.exports = VueCharts
|
||||
|
||||
44
src/mixins/reactiveData.js
Normal file
44
src/mixins/reactiveData.js
Normal file
@@ -0,0 +1,44 @@
|
||||
module.exports = {
|
||||
data () {
|
||||
return {
|
||||
chartData: null
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
'chartData': {
|
||||
handler (newData, oldData) {
|
||||
if (oldData) {
|
||||
let chart = this._chart
|
||||
|
||||
let newDataLabels = newData.datasets.map((dataset) => {
|
||||
return dataset.label
|
||||
})
|
||||
|
||||
let oldDataLabels = oldData.datasets.map((dataset) => {
|
||||
return dataset.label
|
||||
})
|
||||
|
||||
if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) {
|
||||
this.forceUpdate(newData, chart)
|
||||
} else {
|
||||
this.forceRender()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
forceUpdate (newData, chart) {
|
||||
newData.datasets.forEach((dataset, i) => {
|
||||
chart.data.datasets[i].data = dataset.data
|
||||
})
|
||||
|
||||
chart.data.labels = newData.labels
|
||||
chart.update()
|
||||
},
|
||||
|
||||
forceRender () {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
}
|
||||
}
|
||||
35
src/mixins/reactiveProp.js
Normal file
35
src/mixins/reactiveProp.js
Normal file
@@ -0,0 +1,35 @@
|
||||
module.exports = {
|
||||
props: {
|
||||
chartData: {
|
||||
required: true
|
||||
}
|
||||
},
|
||||
|
||||
watch: {
|
||||
'chartData': {
|
||||
handler (newData, oldData) {
|
||||
if (oldData) {
|
||||
let chart = this._chart
|
||||
|
||||
let newDataLabels = newData.datasets.map((dataset) => {
|
||||
return dataset.label
|
||||
})
|
||||
|
||||
let oldDataLabels = oldData.datasets.map((dataset) => {
|
||||
return dataset.label
|
||||
})
|
||||
|
||||
if (JSON.stringify(newDataLabels) === JSON.stringify(oldDataLabels)) {
|
||||
newData.datasets.forEach((dataset, i) => {
|
||||
chart.data.datasets[i].data = dataset.data
|
||||
})
|
||||
chart.data.labels = newData.labels
|
||||
chart.update()
|
||||
} else {
|
||||
this.renderChart(this.chartData, this.options)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
},
|
||||
"globals": {
|
||||
"expect": true,
|
||||
"jasmine": true,
|
||||
"sinon": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ module.exports = function (config) {
|
||||
// http://karma-runner.github.io/0.13/config/browsers.html
|
||||
// 2. add it to the `browsers` array below.
|
||||
browsers: ['PhantomJS'],
|
||||
frameworks: ['mocha', 'sinon-chai'],
|
||||
frameworks: ['mocha', 'sinon-chai', 'jasmine'],
|
||||
reporters: ['spec', 'coverage'],
|
||||
files: ['./index.js'],
|
||||
preprocessors: {
|
||||
|
||||
0
test/unit/specs/mixins/reactiveData.js
Normal file
0
test/unit/specs/mixins/reactiveData.js
Normal file
Reference in New Issue
Block a user