1.在main.js裏需要增加的內容:
import echarts from 'echarts'
Vue .prototype.$echarts=echarts;
2.main.vue裏的內容:
- <template>
- <div>
- <div style = "height:400px" id="mychart1"></div>
- <div style = "height:400px" id="mychart2"></div>
- </div>
- </template>
- <script>
- export default {
- name: "ZongJie",
- components: {},
- data() {
- return {
- mychart1: "", //圖表1
- mychart2: "" //圖表2
- };
- },
- created() {
- this.$nextTick(() => {
- this.init1(), this.init2()
- });
- },
- mounted() {
- let _this = this;
- //圖表自適應 ,自動刷新, 寫法1刷新圖表本身,寫法3刷新整個頁面
- // //寫法1
- // window.onresize = function() {
- // _this.mychart1.resize(),
- // _this.mychart2.resize()
- // };
- this.init1();
- this.init2();
- //寫法2
- window.onload=function(){
- function rand(){
- contain = document.getElementById("contain");
- i=Math.random()*5;
- contain.innerHTML=i;
- }
- window.onresize=function(){
- window.location.reload();
- rand();
- }
- rand();
- }
- },
- methods: {
- init1() {
- this.mychart1 = this.$echarts.init(document.getElementById("mychart1"));
- this.mychart1.setOption({
- title: {
- text: "Average Time For Deal",
- x: "5%",
- y: "5%",
- textStyle: {
- color: "white", //標題
- fontSize: "0.1rem"
- }
- },
- textStyle: {
- color: "white" //XY字體
- // // lineHeight:40,
- },
- // legend: {
- // top:20,
- // textStyle:{
- // color:"white",//ab字體
- // }
- // },
- toolbox: {
- // itemStyle:15,
- feature: {
- // saveAsImage: {},
- restore: { show: true }, //重置
- dataZoom: { show: true },
- brush: { type: ["clear"] }
- }
- },
- dataset: {
- source: [
- ["product", "a", "b"],
- ["2012", 77, 80],
- ["2013", 86.5, 92.1],
- ["2014", 44, 67.2],
- ["2015", 66, 67.2],
- ["2016", 66, 33]
- ]
- },
- xAxis: {
- type: "category",
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)" //x
- }
- },
- splitLine: {
- show: false
- }
- },
- yAxis: {
- min: 0,
- max: 100,
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)" //y
- }
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: "rgb(61,70,79)"
- }
- }
- },
- series: [
- {
- type: "bar",
- itemStyle: {
- color: "rgb(9,192,208)"
- },
- barWidth: "25"
- },
- {
- type: "bar",
- barWidth: "25",
- itemStyle: {
- color: "rgb(20,208,150)"
- }
- }
- ]
- });
- // this.$echartsResize(mychart1);
- },
- init2() {
- this.mychart2 = this.$echarts.init(document.getElementById("mychart2"));
- // var colors = ['#5793f3', '#d14a61', '#675bba'];
- this.mychart2.setOption({
- title: {
- text: "Deals Analytics",
- x: "5%",
- y: "5%",
- textStyle: {
- color: "white",
- fontSize: "0.1rem"
- }
- },
- textStyle: {
- color: "white"
- },
- tooltip: {
- trigger: "axis"
- },
- // legend: {
- // top:20,
- // data:['A', 'B'],
- // textStyle:{
- // color:"white",
- // }
- // },
- grid: {
- top: 70,
- bottom: 50
- },
- toolbox: {
- // itemStyle:15,
- feature: {
- // saveAsImage: {},
- restore: { show: true }, //重置
- dataZoom: { show: true },
- brush: { type: ["clear"] }
- }
- },
- xAxis: {
- type: "category",
- data: ["2013", "2014", "2015", "2016", "2017", "2018", "2019"],
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)"
- },
- splitLine: {
- show: false
- }
- }
- },
- yAxis: {
- type: "value",
- min: 0,
- max: 100,
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)"
- }
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: "rgb(61,70,79)"
- }
- }
- },
- series: [
- {
- smooth: true,
- symbol: "none",
- name: "A",
- type: "line",
- data: [20, 30, 40, 80, 60, 40, 90],
- itemStyle: {
- normal: {
- color: "rgb(42,112,103)",
- lineStyle: {
- color: "rgb(42,112,103)"
- }
- }
- },
- emphasis: {
- color: "rgb(124,62,71)",
- borderColor: "rgb(124,62,71)"
- }
- },
- {
- name: "B",
- smooth: true,
- symbol: "none",
- type: "line",
- data: [30, 20, 70, 50, 40, 90, 30],
- itemStyle: {
- normal: {
- color: "#f672a7",
- lineStyle: {
- color: "#f672a7"
- }
- }
- }
- }
- ]
- });
- // this.$echartsResize(mychart2);
- }
- }
- };
- </script>
- <style scoped lang="stylus">
- </style>
- 在main.js裏需要增加的內容:
-
import echarts from 'echarts'
Vue .prototype.$echarts=echarts;
- main.vue裏的內容:
- <template>
- <div>
- <div style = "height:400px" id="mychart1"></div>
- <div style = "height:400px" id="mychart2"></div>
- </div>
- </template>
- <script>
- export default {
- name: "ZongJie",
- components: {},
- data() {
- return {
- mychart1: "", //圖表1
- mychart2: "" //圖表2
- };
- },
- created() {
- this.$nextTick(() => {
- this.init1(), this.init2()
- });
- },
- mounted() {
- let _this = this;
- //圖表自適應 ,自動刷新, 寫法1刷新圖表本身,寫法3刷新整個頁面
- // //寫法1
- // window.onresize = function() {
- // _this.mychart1.resize(),
- // _this.mychart2.resize()
- // };
- this.init1();
- this.init2();
- //寫法三
- window.onload=function(){
- function rand(){
- contain = document.getElementById("contain");
- i=Math.random()*5;
- contain.innerHTML=i;
- }
- window.onresize=function(){
- window.location.reload();
- rand();
- }
- rand();
- }
- },
- methods: {
- init1() {
- this.mychart1 = this.$echarts.init(document.getElementById("mychart1"));
- this.mychart1.setOption({
- title: {
- text: "Average Time For Deal",
- x: "5%",
- y: "5%",
- textStyle: {
- color: "white", //標題
- fontSize: "0.1rem"
- }
- },
- textStyle: {
- color: "white" //XY字體
- // // lineHeight:40,
- },
- // legend: {
- // top:20,
- // textStyle:{
- // color:"white",//ab字體
- // }
- // },
- toolbox: {
- // itemStyle:15,
- feature: {
- // saveAsImage: {},
- restore: { show: true }, //重置
- dataZoom: { show: true },
- brush: { type: ["clear"] }
- }
- },
- dataset: {
- source: [
- ["product", "a", "b"],
- ["2012", 77, 80],
- ["2013", 86.5, 92.1],
- ["2014", 44, 67.2],
- ["2015", 66, 67.2],
- ["2016", 66, 33]
- ]
- },
- xAxis: {
- type: "category",
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)" //x
- }
- },
- splitLine: {
- show: false
- }
- },
- yAxis: {
- min: 0,
- max: 100,
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)" //y
- }
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: "rgb(61,70,79)"
- }
- }
- },
- series: [
- {
- type: "bar",
- itemStyle: {
- color: "rgb(9,192,208)"
- },
- barWidth: "25"
- },
- {
- type: "bar",
- barWidth: "25",
- itemStyle: {
- color: "rgb(20,208,150)"
- }
- }
- ]
- });
- // this.$echartsResize(mychart1);
- },
- init2() {
- this.mychart2 = this.$echarts.init(document.getElementById("mychart2"));
- // var colors = ['#5793f3', '#d14a61', '#675bba'];
- this.mychart2.setOption({
- title: {
- text: "Deals Analytics",
- x: "5%",
- y: "5%",
- textStyle: {
- color: "white",
- fontSize: "0.1rem"
- }
- },
- textStyle: {
- color: "white"
- },
- tooltip: {
- trigger: "axis"
- },
- // legend: {
- // top:20,
- // data:['A', 'B'],
- // textStyle:{
- // color:"white",
- // }
- // },
- grid: {
- top: 70,
- bottom: 50
- },
- toolbox: {
- // itemStyle:15,
- feature: {
- // saveAsImage: {},
- restore: { show: true }, //重置
- dataZoom: { show: true },
- brush: { type: ["clear"] }
- }
- },
- xAxis: {
- type: "category",
- data: ["2013", "2014", "2015", "2016", "2017", "2018", "2019"],
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)"
- },
- splitLine: {
- show: false
- }
- }
- },
- yAxis: {
- type: "value",
- min: 0,
- max: 100,
- axisLine: {
- onZero: false,
- lineStyle: {
- color: "rgb(61,70,79)"
- }
- },
- splitLine: {
- show: true,
- lineStyle: {
- color: "rgb(61,70,79)"
- }
- }
- },
- series: [
- {
- smooth: true,
- symbol: "none",
- name: "A",
- type: "line",
- data: [20, 30, 40, 80, 60, 40, 90],
- itemStyle: {
- normal: {
- color: "rgb(42,112,103)",
- lineStyle: {
- color: "rgb(42,112,103)"
- }
- }
- },
- emphasis: {
- color: "rgb(124,62,71)",
- borderColor: "rgb(124,62,71)"
- }
- },
- {
- name: "B",
- smooth: true,
- symbol: "none",
- type: "line",
- data: [30, 20, 70, 50, 40, 90, 30],
- itemStyle: {
- normal: {
- color: "#f672a7",
- lineStyle: {
- color: "#f672a7"
- }
- }
- }
- }
- ]
- });
- // this.$echartsResize(mychart2);
- }
- }
- };
- </script>
- <style scoped lang="stylus">
- </style>