gpt4 book ai didi

javascript - 调整内容大小时调整饼图大小

转载 作者:太空宇宙 更新时间:2023-11-03 19:06:01 24 4
gpt4 key购买 nike

我使用 javascript 饼图,如果我设置固定宽度或高度,它工作正常,但如果我设置 100% 宽度和高度,它不显示饼图。当内容调整大小(100%)时,我需要更改宽度和高度。

JS:

    $(function () {
var data = [];
data[0] = { label: "word", data: 25};
data[1] = { label: "withdrawn", data: 75 };
data[2] = { label: "in progress", data: 50 };

$.plot($("#graph-1"), data, {
series: {
pie: {
show: true,
radius: 1,
label: {
show: true,
radius: 2/3,
formatter: function(label, series){
return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/></div>';
},
threshold: 0.1
},
combine: {color: '#666', threshold: 0.1}
}
},
legend: {show: false}
});
});

HTML:

<td class="graph-td">
<div id="graph-1" class="graph-1"></div>
</td>

CSS:

 /* In this case pie chart working norm */
.graph-1 { width:250px; height: 250px; margin: 0 auto;}

/* In this case pie chart is not displaying */
.graph-1 { width:100%; height: 100%; margin: 0 auto;}

最佳答案

$(window).on('resize', function(){


// get container width & height
// destroy your chart
// redraw your chart with new dimensions
// or refresh your chart view, or change the width/height, depending upon how your plugin works

});

关于javascript - 调整内容大小时调整饼图大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10250255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com