echarts象形图pictorialBar

本文详细解读了ECharts中象形柱图的使用方法,包括利用图片和形状表示数据的技巧,以及代码实例和实际效果展示。通过实例演示如何通过图形尺寸、数量和颜色变化展现数据特征。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

象形柱图的官方解释

象形柱图在 ECharts 系列中使用series[i]-pictorialBar表示,它利用图片和形状表现数据,具体来说它既可以用图形的长宽变形表现数据,也可以用图形的个数、甚至是图形的颜色、透明度变化表现数据。
在这里插入图片描述

代码实现

var category = ['服务器数(台)', '计算容量(核)', '内存容量(GB)', '存储容量(PB)'];
var barData = [0, ~~(Math.random() * 100), ~~(Math.random() * 100), ~~(Math.random() * 100), ~~(Math.random() * 100)];
var barData = [60, 30, 52, 34, 90];
var lineData = [63, 63, 63, 63, 100]

// console.log(barData)
var option = {
    // backgroundColor: '#0d073d',//背景色
    grid: [{//图形的位置
        left: '10',
        bottom: '20',
        top: 3,
        right: 30
    }],
    xAxis: {
        show: false//是否展示X轴
    },
    yAxis: {
        data: category,
        show: true,
        axisLabel: {
            inside: true,
            verticalAlign: 'middle',
            lineHeight: 150,
            color: '#4488bc',
            fontSize: 8
        },
        axisLine: {
            show: false//不展示刻度
        }
    },
    series: [{ // 外边框
            name: '',
            type: 'pictorialBar',//echarts图的类型
            symbol: 'reat',//内部类型(方块,圆,svg,base64图片)
            barWidth: '3%',
            barMaxWidth: '10%',
            symbolOffset: [70, 0],//柱子的位置
            symbolSize: [130, 20],//size,单个symbol的大小
            itemStyle: {
                normal: {
                    color: '#3f559c'
                }
            },
            z: -180,//图层值
            symbolRepeat: null,//是否重复symbol
            data: [1, 1, 1, 1],
            barGap: 50,//柱子的“粗细”
            barCategoryGap: 0,
            animationEasing: 'elasticOut',

        },
        { // 内边框
            name: '',
            type: 'pictorialBar',
            symbol: 'reat',
            barWidth: '3%',
            barMaxWidth: '20%',
            symbolOffset: [72, 0],
            symbolSize: [125, 18],
            itemStyle: {
                normal: {

                    color: '#0d073d'
                }
            },
            z: -20,
            symbolRepeat: null,
            data: [1, 1, 1, 1],
            barGap: 45,
            barCategoryGap: 0,
            animationEasing: 'elasticOut',

        },

        { // 下层块
            name: '',
            type: 'pictorialBar',
            symbol: 'roundRect',
            barWidth: '3%',
            barMaxWidth: '20%',
            symbolOffset: [75, 0],
            itemStyle: {
                normal: {

                    color: '#1F4683'
                }
            },
            z: -11,
            symbolRepeat: true,
            symbolSize: [6, 16],
            data: lineData,
            barGap: 50,
            barCategoryGap: 0,
            animationEasing: 'elasticOut',

        },

        { // 上层块
            name: '', // blue bar
            type: 'pictorialBar',
            symbol: 'roundRect',
            barWidth: '3%',
            barMaxWidth: 100,
            symbolOffset: [75, 0],
            itemStyle: {
                normal: {
                    barMaxWidth: '20%',
                    barBorderRadius: 100,
                    color: '#6DE8FA',

                }
            },
            symbolRepeat: true,
            symbolSize: [6, 16],
            // symbolClip: true,
            data: barData,
        },
        /* 
         */

    ],

}

实现的效果:
在这里插入图片描述

这里是引用:https://www.jianshu.com/p/0632b3e773d9

### 关于 ECharts 象形图图例配置 在 ECharts 中,象形柱图是一种特殊的柱状图形式,允许使用自定义图形(如图片、SVG 或 PathData)作为柱子形状[^3]。对于象形图来说,其图例配置与其他类型的图表基本一致,主要通过 `legend` 属性来进行控制。 #### 基本图例配置 为了使图例能够正确显示并关联到对应的系列数据,在初始化选项时需指定 `legend` 对象以及各系列中的 `name` 字段: ```javascript option = { legend: { // 定义图例组件 data: ['Series A', 'Series B'] // 设置图例项名称列表 }, series: [ { name: 'Series A', // 系列名应与图例项对应 type: 'pictorialBar', symbol: 'path://...', // 自定义图标路径或内置类型 ... }, { name: 'Series B', type: 'pictorialBar', symbol: 'image://url_to_image',// 使用图像URL代替默认矩形条 ... } ] }; ``` #### 进阶配置实例 当希望进一步定制化图例样式时,可以通过调整更多参数来优化用户体验。例如改变图例位置、文字颜色等: ```javascript option = { legend: { orient: 'vertical', // 图例垂直排列 x: 'right', // 放置于右侧 textStyle: { // 文字风格设定 color: '#fff' } }, toolbox: {}, // 可选工具箱配置 tooltip: {}, xAxis: [{type: 'category'}], yAxis: [{type: 'value'}], series: [{ name: 'Example Series', type: 'pictorialBar', symbolSize: function (val) { // 动态尺寸函数 return Math.sqrt(val); }, itemStyle: { normal: { label: {show: true} } } }] }; ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值