使用apexcharts组件的折线图(smooth的面积曲线)

  1. 引入组件
    import VueApexCharts from 'vue-apexcharts'

  2. 页面使用组件

        <template>
            <vue-apex-charts class="vx-col w-1/3"
                                    height=250
                                    type="area"
                                    :options="crudProfile.option"
                                    :series="crudProfile.series"/>
        </template>
    
        components: {
            VueApexCharts
        }
    
  3. 数据格式

    crudProfile: {
        series: [],
        option: {}
    }
    
  4. 初始化数据

        mounted () {
            this.drawCrudGraph(data) 
            /*
                data: 是传下来的折线图的series数据
                data的数据格式为:
                [
                    {
                        name: 'series1',
                        data: [31, 40, 28, 51, 42, 109, 100]
                    }, 
                    {
                        name: 'series2',
                        data: [11, 32, 45, 32, 34, 52, 41]
                    },
    			]
            */ 
        }
    
  5. 给页面折线图赋值以及设置其option。可以参照官网:https://apexcharts.com/docs/installation/#

    methods: {
        drawCrudGraph (crudData) {
            this.getCrudOption()
            this.crudProfile.series = crudData
        },
        getCrudOption () {
            this.crudProfile.option = {
                title: { // 显示折现图的title
                    text: '总体性能(平均响应速度)',
                    fontSize: '12px'
                },
                dataLabels: {
                    enabled: false // 启用数据标签,即是否直接在图标上显示数据
                },
                chart: {
                    height: 250,
                    toolbar: { show: false }, // // 是否显示右上角默认图标
                    /*
                        属性见官网: https://apexcharts.com/docs/options/chart/toolbar/
                        如果想要自定义图表即对应的方法,则在customIcons: [] 设置。
                        比如:
                            customIcons: [{
                                icon: '<img src="" width="20">',
                                index: 4,
                                title: '按钮1',
                                class: 'custom-icon',
                                click: function(chart, options, e) {
                                    console.log("clicked custom-icon")
                                }
                            },
                            {
                                icon: '<img src="" width="20">',
                                index: 4,
                                title: '按钮2',
                                class: 'custom-icon',
                                click: function(chart, options, e) {
                                    console.log("clicked custom-icon")
                                }
                            }]
                    */
                    type: 'area' // 图表类型:line、area、bar、radar、pie等
                },
                <!-- plotOptions: {
                    bar: {
                        horizontal: true, // 展示为水平折线图
                        // columnWidth: '60%',
                    },
                }, -->
                grid: {
                    borderColor: '#cdcdcd', // 网格边框/线条的颜色
                    width: 1,
                    strokeDashArray: 2 // 在路径中创建虚线
                },
    
                stroke: {
                    curve: 'smooth', // 在折线图/面积图中,是绘制平滑线还是直线可用选项
                    width: [2, 2, 2]
                },
    
                legend: {
                    show: true,
                    position: 'top',
                    width: 'auto'
                },
    
                fill: {
                type: 'gradient',
                gradient: {
                    shadeIntensity: 0.9,
                    opacityFrom: 0.7,
                    opacityTo: 0.5,
                    stops: [0, 80, 100]
                }
                },
    
                xAxis: {
                    labels: {
                        style: {
                        cssClass: 'text-grey fill-current'
                        }
                    },
                    axisTicks: {
                        show: true
                    },
                    categories: [], // x轴显示的值
                    axisBorder: {
                        show: true
                    }
                },
    
                yAxis: {
                    tickAmount: 5
                },
    
                tooltip: {
                    x: { show: true }
                }
            }
        }
    }
    
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值