| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <template>
- <view>
- <div class="chart1" ref="chart"></div>
- </view>
- </template>
-
- <script>
- import echarts from "echarts";
- export default {
- props: {
- // beforeFan:{
- // type: Array,
- // // 定义是否必须传
- // required: false,
- // // 定义默认值
- // default: []
- // },
- },
- mounted() {
- this.getEchartData()
- },
- data() {
- return {
- }
- },
-
- methods: {
- // 折线图
- getEchartData() {
- const chart = this.$refs.chart;
- var option = null;
- const myChart = this.$echarts.init(chart);
- option = {
- legend: {
- top: 20,
- },
- color:'rgb(128, 128, 255)',
- grid: {
- left: '3%',
- right: '4%',
- bottom: '34%',
- containLabel: true
- },
- xAxis: {
- type: 'value'
- },
- yAxis: {
- type: 'category',
- data: ['41岁及以上', '36-40岁', '31-35岁', '25-30岁', '24岁及以下']
- },
- series: [
- {
- name: '人数',
- type: 'bar',
- stack: 'total',
- label: {
- show: true
- },
- emphasis: {
- focus: 'series'
- },
- data: [320, 302, 301, 334, 390, 330, 320]
- },
- ]
- };
- myChart.setOption(option);
- window.addEventListener("resize", function () {
- myChart.resize();
- });
- this.$on("hook:destroyed", () => {
- window.removeEventListener("resize", function () {
- chart.resize();
- });
- });
- return option;
- },
-
- },
-
- }
- </script>
- <style>
- .chart1 {
- width: 100%;
- height: 135%;
- display: block;
- }
- </style>
|