Skip to content

Commit cea532e

Browse files
authored
Merge pull request #9 from lin-xin/dev
release:V2.0.0
2 parents 7b1f93f + 91e1ae9 commit cea532e

File tree

7 files changed

+172
-165
lines changed

7 files changed

+172
-165
lines changed

LICENCE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017 林鑫
3+
Copyright (c) 2017-2019 林鑫
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+24-18
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
Support for use at the mobile. Support vue.js 1.x & 2.x
1313

14-
[interactive demo](http://blog.gdfengshuo.com/example/#/vue-schart)
15-
1614
## Usage
1715

1816
Install:
@@ -26,24 +24,36 @@ Use in component:
2624
```html
2725
<template>
2826
<div id="app">
29-
<schart class="wrapper" :canvasId="canvasId" :type="type" :data="data" :options="options"></schart>
27+
<schart class="wrapper" canvasId="canvas" :options="options" />
3028
</div>
3129
</template>
3230
<script>
33-
import Schart from 'vue-schart';
31+
import Schart from 'vue-schart';
3432
export default {
3533
data() {
3634
return {
37-
canvasId: 'myCanvas',
38-
type: 'bar',
39-
data: [
40-
{name: '2014', value: 1342},
41-
{name: '2015', value: 2123},
42-
{name: '2016', value: 1654},
43-
{name: '2017', value: 1795},
44-
],
4535
options: {
46-
title: 'Total sales of stores in recent years'
36+
type: "bar",
37+
title: {
38+
text: "最近一周各品类销售图"
39+
},
40+
bgColor: "#fbfbfb",
41+
labels: ["周一", "周二", "周三", "周四", "周五"],
42+
datasets: [
43+
{
44+
label: "家电",
45+
fillColor: "rgba(241, 49, 74, 0.5)",
46+
data: [234, 278, 270, 190, 230]
47+
},
48+
{
49+
label: "百货",
50+
data: [164, 178, 190, 135, 160]
51+
},
52+
{
53+
label: "食品",
54+
data: [144, 198, 150, 235, 120]
55+
}
56+
]
4757
}
4858
}
4959
},
@@ -62,11 +72,7 @@ import Schart from 'vue-schart';
6272
```
6373
## Options
6474

65-
Refer to [the documentation for sChart.js](http://blog.gdfengshuo.com/example/sChart/).
66-
67-
## Demo
68-
69-
![demo](http://blog.gdfengshuo.com/example/sChart/static/img/demo.png)
75+
Refer to [the documentation for sChart.js](https://lin-xin.gitee.io/example/schart/).
7076

7177
## License
7278
[MIT license](https://github.com/lin-xin/vue-schart/blob/master/LICENCE).

example/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules"
1111
},
1212
"dependencies": {
13-
"schart.js": "^2.0.0",
13+
"schart.js": "^3.0.0",
1414
"vue": "^2.5.11"
1515
},
1616
"browserslist": [

example/src/App.vue

+70-46
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,80 @@
11
<template>
2-
<div id="app">
3-
<schart class="wrapper" :canvasId="canvasId" :type="type" :data="data" :options="options"></schart>
4-
<schart class="wrapper" canvasId="canvas1" type="pie" :data="data" :options="options"></schart>
5-
<button @click="change">change</button>
6-
</div>
2+
<div id="app">
3+
<schart class="wrapper" canvasId="canvas" :options="options"></schart>
4+
<button @click="change('bar')">change to bar</button>
5+
<button @click="change('line')">change to line</button>
6+
<button @click="change('pie')">change to pie</button>
7+
<button @click="change('ring')">change to ring</button>
8+
</div>
79
</template>
810

911
<script>
10-
import Schart from './vue-schart.vue';
12+
import Schart from "./vue-schart";
1113
export default {
12-
name: 'app',
13-
data () {
14-
return {
15-
flag: false,
16-
canvasId: 'myCanvas',
17-
type: 'bar',
18-
data: [
19-
{name: '2014', value: 1342},
20-
{name: '2015', value: 2123},
21-
{name: '2016', value: 841},
22-
{name: '2015', value: 2123},
23-
{name: '2016', value: 589},
24-
{name: '2017', value: 1795},
25-
],
26-
options: {
27-
title: 'Total sales of stores in recent years',
28-
bottomPadding: 30
29-
}
14+
name: "app",
15+
data() {
16+
return {
17+
options: {
18+
type: "bar",
19+
title: {
20+
text: "最近一周各品类销售图"
21+
},
22+
bgColor: "#fbfbfb",
23+
labels: ["周一", "周二", "周三", "周四", "周五"],
24+
datasets: [
25+
{
26+
label: "家电",
27+
fillColor: "rgba(241, 49, 74, 0.5)",
28+
data: [234, 278, 270, 190, 230]
29+
},
30+
{
31+
label: "百货",
32+
data: [164, 178, 190, 135, 160]
33+
},
34+
{
35+
label: "食品",
36+
data: [144, 198, 150, 235, 120]
37+
}
38+
]
39+
}
40+
};
41+
},
42+
created() {
43+
this.getData();
44+
},
45+
components: {
46+
Schart
47+
},
48+
methods: {
49+
getData() {
50+
setTimeout(() => {
51+
const data = [
52+
{
53+
label: "家电",
54+
fillColor: "rgba(241, 49, 74, 0.5)",
55+
data: [234, 278, 270, 190, 230]
56+
},
57+
{
58+
label: "百货",
59+
data: [164, 178, 190, 135, 160]
60+
},
61+
{
62+
label: "食品",
63+
data: [144, 198, 150, 235, 120]
64+
}
65+
];
66+
this.$set(this.options1, "datasets", data);
67+
}, 1000);
68+
},
69+
change(type) {
70+
this.$set(this.options1, "type", type);
71+
}
3072
}
31-
},
32-
components:{
33-
Schart
34-
},
35-
methods: {
36-
change(){
37-
this.data = [
38-
{name: '2015', value: 2123},
39-
{name: '2016', value: 589},
40-
{name: '2017', value: 1795},
41-
{name: '2014', value: 1342},
42-
];
43-
this.type = 'line';
44-
this.$set(this.options, 'title', '哈哈哈哈哈哈')
45-
}
46-
}
47-
}
73+
};
4874
</script>
4975
<style>
50-
.wrapper{
51-
width: 500px;
52-
height: 400px;
53-
/* width: 7rem;
54-
height: 5rem; */
76+
.wrapper {
77+
width: 500px;
78+
height: 400px;
5579
}
5680
</style>

example/src/vue-schart.vue

+36-47
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,48 @@
55
</template>
66

77
<script>
8-
import sChart from 'schart.js';
9-
export default {
10-
data() {
11-
return {
12-
schart: null,
13-
opt: {}
14-
}
8+
import Schart from "schart.js";
9+
export default {
10+
props: {
11+
canvasId: {
12+
type: String,
13+
default: "",
14+
required: true
1515
},
16-
props: {
17-
canvasId: {
18-
type: String,
19-
default: ''
20-
},
21-
type: {
22-
type: String,
23-
default: 'bar',
24-
},
25-
data: {
26-
type: Array,
27-
default: [],
28-
},
29-
options: {
30-
type: Object,
31-
required: false
16+
options: {
17+
type: Object,
18+
required: true
19+
}
20+
},
21+
mounted() {
22+
this.renderChart();
23+
},
24+
methods: {
25+
renderChart() {
26+
if (!this.checkOptions()) {
27+
return;
3228
}
29+
const opt = { ...this.options };
30+
new Schart(this.canvasId, opt);
3331
},
34-
mounted() {
35-
this.renderChart();
36-
},
37-
methods: {
38-
renderChart(){
39-
this.schart = null;
40-
this.opt = this.options;
41-
if(!this.width || !this.height){
42-
if(!this.opt){
43-
this.opt = {autoWidth: true};
44-
}else{
45-
this.opt['autoWidth'] = true;
46-
}
47-
}
48-
this.schart = new sChart(this.canvasId, this.type, this.data, this.opt);
32+
checkOptions() {
33+
const opt = this.options;
34+
if (!opt.datasets || !opt.datasets.length) {
35+
return false;
4936
}
50-
},
51-
watch: {
52-
data(){
53-
this.renderChart();
54-
},
55-
options(){
37+
if (!opt.labels || !opt.labels.length) {
38+
return false;
39+
}
40+
return true;
41+
}
42+
},
43+
watch: {
44+
options: {
45+
handler(newValue, oldValue) {
5646
this.renderChart();
5747
},
58-
type(){
59-
this.renderChart();
60-
}
48+
deep: true
6149
}
6250
}
51+
};
6352
</script>

package.json

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
{
22
"name": "vue-schart",
33
"description": "Vue.js wrapper for sChart.js",
4-
"version": "1.0.0",
4+
"version": "2.0.0",
55
"author": "lin-xin <[email protected]>",
66
"main": "src/vue-schart.vue",
7-
"scripts": {
8-
},
7+
"scripts": {},
98
"dependencies": {
10-
"schart.js": "^2.0.0"
9+
"schart.js": "^3.0.0"
1110
},
1211
"repository": {
1312
"type": "git",
@@ -24,4 +23,4 @@
2423
"bugs": {
2524
"url": "https://github.com/lin-xin/vue-schart/issues"
2625
}
27-
}
26+
}

0 commit comments

Comments
 (0)