vue+element+echarts柱状图+列表

前端由vue+element搭建框架,引入vue和element的index.js和css就可以写页面;

 页面和js可以echarts官网实例看下都是有的,主要看下如何动态赋值:

柱状图和列表:

<script type="text/javascript" src="/main/common/echarts/echarts.min.js"></script>

<
div id="echart" style="width: 100%;height: 300px;margin-bottom: 10px"></div>
<el-table :data="tableData" border style="margin: 0 auto" row-class-name="row_padding"
                      header-row-class-name="head_padding">
                <el-table-column fixed prop="processDeptName" label="单位名称" align="center" width="150" show-overflow-tooltip></el-table-column>
                <el-table-column prop="acceptCount" label="本单位受理量"  align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="totalCount" label="办理总量"  align="center" show-overflow-tooltip></el-table-column>         
                <el-table-column prop="completedCount" label="正常完成"  align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="completedOverCount" label="超时完成"  align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="processCount" label="正常处理"  align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="processOverCount" label="超时处理"  align="center" show-overflow-tooltip></el-table-column>
                <el-table-column prop="completedPercent" label="完成率"  align="center" show-overflow-tooltip></el-table-column>
            </el-table>

js:

var vue = new Vue({
    el: '#app',
    data: {
        tableData:[],
    },
    created: function () {
        this.initTable();
    },

getChartOption(data){
            var option = {
                title: {
                    text: '按办理单位任务统计',
                    x:'center',
                    textAlign:'left',
                    top:'3%'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow'
                    }
                },
                grid: {
                    left: '1%',
                    right: '1%',
                    top: '15%',
                    bottom:'10%',
                    containLabel: true
                },
                backgroundColor:'#fff',
                xAxis: {
                    type: 'category',
                    data: data.nameList,
                    axisLine:{
                        lineStyle:{
                            color:'#9a9a9a'
                        }
                    }
                },
                yAxis: {
                    type: 'value',
                    axisLine:{
                        lineStyle:{
                            color:'#9a9a9a'
                        }
                    }
                },
                series: [{
                    data: data.valueList,
                    type: 'bar',
                    itemStyle:{
                        normal:{
                            color:'#427aff'
                        }
                    }
                }]
            };
            return option;
        },
var ele=document.getElementById('echart');
                            var myChart = echarts.init(ele);
                            var option=self.getChartOption({
                                nameList:nameList,
                                valueList:valueList
                            });
                            myChart.setOption(option);
                            window.onresize = myChart.resize;

 效果:

 

转载于:https://www.cnblogs.com/wmqiang/p/11008769.html

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是基于 Vue.jsElement UI 组件库实现的柱状图示例: 1. 安装 Element UI 组件库并按需引入相应组件: ``` npm i element-ui -S ``` ```js // 在 main.js 中按需引入组件 import Vue from 'vue'; import { Button, Select, Option, Row, Col, Input, Form, FormItem, Loading, Message, MessageBox, Notification, Container, Header, Aside, Main, Menu, Submenu, MenuItem, MenuItemGroup, Breadcrumb, BreadcrumbItem, Card, Table, TableColumn, Pagination, Dialog, Dropdown, DropdownMenu, DropdownItem, Tabs, TabPane, Checkbox, CheckboxGroup, Radio, RadioGroup, Switch, DatePicker, TimePicker, Upload, Steps, Step, Carousel, CarouselItem, Tooltip, Popover, Alert, Tag, Badge, Progress, Tree, Cascader, Avatar, Divider, Image, Popconfirm, Slider, Transfer, ColorPicker, Scrollbar, Collapse, CollapseItem } from 'element-ui'; Vue.use(Button); Vue.use(Select); Vue.use(Option); Vue.use(Row); Vue.use(Col); Vue.use(Input); Vue.use(Form); Vue.use(FormItem); Vue.use(Loading.directive); Vue.prototype.$loading = Loading.service; Vue.prototype.$message = Message; Vue.prototype.$msgbox = MessageBox; Vue.prototype.$alert = MessageBox.alert; Vue.prototype.$confirm = MessageBox.confirm; Vue.prototype.$prompt = MessageBox.prompt; Vue.prototype.$notify = Notification; Vue.use(Container); Vue.use(Header); Vue.use(Aside); Vue.use(Main); Vue.use(Menu); Vue.use(Submenu); Vue.use(MenuItem); Vue.use(MenuItemGroup); Vue.use(Breadcrumb); Vue.use(BreadcrumbItem); Vue.use(Card); Vue.use(Table); Vue.use(TableColumn); Vue.use(Pagination); Vue.use(Dialog); Vue.use(Dropdown); Vue.use(DropdownMenu); Vue.use(DropdownItem); Vue.use(Tabs); Vue.use(TabPane); Vue.use(Checkbox); Vue.use(CheckboxGroup); Vue.use(Radio); Vue.use(RadioGroup); Vue.use(Switch); Vue.use(DatePicker); Vue.use(TimePicker); Vue.use(Upload); Vue.use(Steps); Vue.use(Step); Vue.use(Carousel); Vue.use(CarouselItem); Vue.use(Tooltip); Vue.use(Popover); Vue.use(Alert); Vue.use(Tag); Vue.use(Badge); Vue.use(Progress); Vue.use(Tree); Vue.use(Cascader); Vue.use(Avatar); Vue.use(Divider); Vue.use(Image); Vue.use(Popconfirm); Vue.use(Slider); Vue.use(Transfer); Vue.use(ColorPicker); Vue.use(Scrollbar); Vue.use(Collapse); Vue.use(CollapseItem); ``` 2. 在组件中使用 echarts 绘制柱状图并绑定数据: ```html <template> <div class="chart-container"> <div ref="chart" class="chart"></div> </div> </template> <script> import echarts from 'echarts'; export default { name: 'BarChart', data() { return { chartData: [ { month: '一月', sales: 1000 }, { month: '二月', sales: 1200 }, { month: '三月', sales: 800 }, { month: '四月', sales: 1500 }, { month: '五月', sales: 1300 }, { month: '六月', sales: 1700 }, { month: '七月', sales: 900 } ] } }, mounted() { // 基于准备好的dom,初始化echarts实例 let myChart = echarts.init(this.$refs.chart); // 指定图表的配置项和数据 let option = { title: { text: '月度销售额', subtext: '单位:元' }, tooltip: {}, xAxis: { data: this.chartData.map(item => item.month), axisLabel: { interval: 0, // 强制显示所有刻度标签 rotate: 45, // 旋转角度 margin: 10 // 刻度标签与轴线之间的距离 } }, yAxis: {}, series: [{ name: '销售额', type: 'bar', data: this.chartData.map(item => item.sales), itemStyle: { // 柱形图圆角 barBorderRadius: 5 } }] }; // 使用刚指定的配置项和数据显示图表。 myChart.setOption(option); } } </script> <style scoped> .chart-container { width: 100%; height: 400px; display: flex; justify-content: center; align-items: center; } .chart { width: 80%; height: 80%; } </style> ``` 以上就是基于 Vue.jsElement UI 组件库实现的柱状图示例。其中,echarts 是一个非常强大的数据可视化库,可以通过配置项和数据来绘制各种类型的图表。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值