首页 新闻 会员 周边

如何修改echarts的dom下的canvas的宽度自适应

0
悬赏园豆:15 [待解决问题]

//三种占比
var myChartType = echarts.init(document.getElementById('type_chart'));
var gailanTotal = "";
option = {
legend: {
icon: "circle",
orient: 'vertical',
right: 50,
bottom: 20,
selectedMode: false, //取消图例上的点击事件
data: ['轿车', 'SUV', 'MPV']
},
tooltip: {
trigger: 'item',
formatter: "{a} <br/>{b}: {c} ({d}%)",

},
grid: {
    left: '0',
    right: '0',
    top: '0',
    bottom: '0'
},
//环形颜色
color: ['#0C7BE3', '#5BA1E3', '#88B7E3'],
// 设置环形中间的数据
graphic: [{
    type: 'text',
    left: '34%',
    top: '55%',
    z: 10,
    style: {
        fill: '#1a1a1a',
        text: gailanTotal,
        font: '16px Microsoft YaHei'
    }
}],
series: [{
    name: '访问来源',
    type: 'pie',
    radius: ['35%', '55%'], //两个表示环:内半径,外半径
    center: ['43%', '58%'], //左右,上下
    avoidLabelOverlap: false,
    label: {
        normal: {
            show: true,
            position: 'outer',
            // formatter: '{d}%, {c} \n\n',
            //模板变量有 {a}, {b},{c},{d},{e},分别表示系列名,数据名,数据值等。
            formatter: "{a_set|{b},{d}%}\n{c_set|{c}辆}\n\n\n",
            borderWidth: 20,
            borderRadius: 4,
            padding: [90, -50],
            rich: {
                a_set: {
                    color: "#1a1a1a",
                    lineHeight: 20,
                    align: "center"
                },
                c_set: {
                    color: "#808080",
                }

            }
        },
        emphasis: {
            show: true,
            textStyle: {
                fontSize: '30',
                fontWeight: 'bold',
            }
        }
    },
    //牵引线条颜色
    labelLine: {
        normal: {
            show: true,
            length: 30,
            length2: 50,
            lineStyle: {
                color: '#808080'
            },
        }
    },
    data: [],
}]

};
myChartType.setOption(option);
写了
window.onresize = function(){
console.log(11);
myChartType.resize();
myChart.resize();
}
还是不行,求指教!!!

凹凸曼啦的主页 凹凸曼啦 | 初学一级 | 园豆:189
提问于:2020-03-25 10:02
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册