在bootstrap的container中实现echart的饼图

这篇博客展示了如何在Bootstrap的container内嵌入并调整ECharts饼图。通过设置HTML和JS代码,实现了饼图的显示,并确保图表在窗口大小改变时能够自动调整尺寸,以适应Bootstrap的响应式布局。

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

html中的代码如下<div id="dash_show" class="container_m"> <div class="row" style="height:60%;margin-top:25px;">
                         <div class="col-md-9">
                             <div id="chart_daily_movement">
                                 <div id="chart_daily_movement" style="width:100%;height:320px;"></div>
                             </div>
                         </div>

<div><div>

JS文件中的代码function generateChart_movement(h, l) {
    var myChart2 = echarts.init(document.getElementById('chart_daily_movement'));
    var resizeWorldMapContainer2 = function () {
        $("#chart_movement_content").width = window.innerWidth * 0.33 + 'px';
        myChart2.resize();
    };
     option = {
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                x: 'left',
                data: ['Average Inventory', 'Shipment', ]
            },
            color: ['rgb(5,188,254)', 'rgb(156,220,87)'],
            toolbox: {
                show: false,
                feature: {
                    mark: { show: true },
                    dataView: { show: true, readOnly: false },
                    magicType: {
                        show: true,
                        type: ['pie', 'funnel'],
                        option: {
                            funnel: {
                                x: '25%',
                                width: '50%',
                                funnelAlign: 'center',
                                max: 1548
                            }
                        }
                    },
                    restore: { show: true },
                    saveAsImage: { show: true }
                }
            },
            calculable: true,
            series: [
                {
                    name: '',
                    type: 'pie',
                    radius: ['50%', '70%'],
                    itemStyle: {
                        normal: {
                            label: {
                                show: false
                            },
                            labelLine: {
                                show: false
                            }
                        },
                        emphasis: {
                            label: {
                                show: true,
                                position: 'center',
                                textStyle: {
                                    fontSize: '12',
                                    fontWeight: 'bold'
                                }
                            }
                        }
                    },
                    data: [
                        { value: h, name: 'Average Inventory' },
                        { value: l, name: 'Shipment' },
                    ]
                }
            ]     
    };
    var myChart2 = echarts.init(document.getElementById('chart_daily_movement'));
    myChart2.setOption(option);
    window.addEventListener("resize", function () {                         //bootstrap下的resize的实现方法
        myChart2.resize();
    });
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值