-
-
Notifications
You must be signed in to change notification settings - Fork 837
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from apertureless/feature/documentation
Feature/documentation
- Loading branch information
Showing
25 changed files
with
402 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
vue-chartjs.org |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,280 @@ | ||
--- | ||
search: english | ||
--- | ||
|
||
# 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` 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 -S` | ||
|
||
If you are using vue 1.x please use the `legancy` tag. However the vue 1 version is not maintained anymore. | ||
|
||
`yarn add vue-chartjs@legacy -S` | ||
|
||
## Quick Start | ||
|
||
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 | | ||
| 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> | ||
``` | ||
|
||
## 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"> | ||
The bar chart has an **optional** third parameter, which is the type. | ||
The default type is `bar` but you can pass `horizontalBar` if you want horizontal bars. | ||
|
||
`renderChart (data, options, type) {}` | ||
|
||
</p> | ||
|
||
![Bar](assets/bar.png) | ||
### Line Chart | ||
|
||
![Line](assets/line.png) | ||
|
||
### Doughnut | ||
|
||
![Doughnut](assets/doughnut.png) | ||
|
||
### Pie | ||
|
||
![Pie](assets/pie.png) | ||
|
||
### Radar | ||
|
||
![Pie](assets/radar.png) | ||
|
||
### Polar Area | ||
|
||
![Pie](assets/polar.png) | ||
|
||
### Bubble | ||
|
||
![Bubble](assets/bubble.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<h1>📈 vue-chartjs</h1> | ||
|
||
<h2>⚡ Easy and beautiful charts with Chart.js and Vue.js</h2> | ||
|
||
<ul class="features"> | ||
<li>Easy for both beginners and pros 🙌</li> | ||
<li>Simple to use, easy to extend 💪</li> | ||
<li>With the full power of chart.js 💯</li> | ||
</ul> | ||
|
||
<div class="landing-buttons"> | ||
<a class="landing-button" target="_blank" href="https://github.com/apertureless/vue-chartjs"> | ||
GitHub | ||
</button> | ||
|
||
<a class="landing-button" router-link="/home"> | ||
Docs | ||
</a> | ||
|
||
<a class="landing-button" target="_blank" href="http://demo.vue-chartjs.org/"> | ||
Demo | ||
</a> | ||
</div> | ||
|
||
<style> | ||
h1 { | ||
margin: 0; | ||
margin-top: -50px; | ||
font-weight: normal; | ||
font-size: 40px; | ||
letter-spacing: 1px; | ||
} | ||
h2 { | ||
margin-top: 20px; | ||
color: #999; | ||
font-weight: normal; | ||
letter-spacing: 1px; | ||
} | ||
.landing { | ||
padding: 10px; | ||
display: -webkit-box; | ||
display: -ms-flexbox; | ||
display: flex; | ||
-webkit-box-align: center; | ||
-ms-flex-align: center; | ||
align-items: center; | ||
-webkit-box-pack: center; | ||
-ms-flex-pack: center; | ||
justify-content: center; | ||
-webkit-box-orient: vertical; | ||
-webkit-box-direction: normal; | ||
-ms-flex-direction: column; | ||
flex-direction: column; | ||
height: 100%; | ||
-webkit-user-select: none; | ||
user-select: none; | ||
} | ||
.features { | ||
margin-top: 20px; | ||
margin-bottom: 60px; | ||
font-size: 16px; | ||
line-height: 1.7; | ||
} | ||
.landing-button { | ||
border: 1px solid #ccc; | ||
border-radius: 33px; | ||
padding: 10px 30px; | ||
background-color: white; | ||
display: inline-block; | ||
margin-right: 20px; | ||
color: #333; | ||
} | ||
.landing-button:hover { | ||
border-color: #42b983; | ||
color: #42b983; | ||
text-decoration: none; | ||
} | ||
</style> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
self.$config = { | ||
plugins: [ | ||
evanyou() | ||
], | ||
landing: true, | ||
// or custom path | ||
landing: '_landing.html', | ||
repo: 'apertureless/vue-chartjs', | ||
twitter: 'apertureless', | ||
'edit-link': 'https://github.com/apertureless/vue-chartjs/blob/master/docs' | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.