gpt4 book ai didi

android - Highcharts (PieChart) - 第二次绘制时图表宽度减小

转载 作者:行者123 更新时间:2023-11-30 01:07:08 25 4
gpt4 key购买 nike

首先要感谢 HighCharts。好吧,我正在 jQuery Mobile 中使用 HighCharts 构建饼图。

我正在显示几个饼图(最多 6 个图表),这些饼图是根据响应数据在 Ajax 成功回调中动态创建的。 Ajax 最初在 document.ready() 中调用,在单击按钮时也会调用。

document.ready() 创建饼图的过程中,所有图表都水平居中显示在屏幕上,这是预期的结果。但是下次当它从按钮点击创建时,它向左移动一点点,即它的宽度比它在 document.ready() 上显示的要小。

我正在创建每个容器 <div id="container-x"></div>动态饼图。
这是我用来创建图表的示例代码。 dataArray 是用于绘制饼图的数据集。

$('#container' + i).highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie',
marginBottom: 150,
marginLeft: 20
},
title: {
text: ''
},
tooltip: {
pointFormat: '<b>{point.y:.0f}</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
showInLegend: true,
dataLabels: {
enabled: true,
useHTML: true,
formatter: function () {
return Math.round(this.percentage * 100) / 100 + '%';
},
style: {
fontWeight: 'bold',
color: 'black'
}
}
}
},
legend: {
layout: 'vertical',
align: 'left',
verticalAlign: 'bottom',
useHTML: true,
maxHeight: 135,
itemMarginTop: 2,
itemMarginBottom: 2,
labelFormatter: function () {
var words = this.name.split(/[\s]+/);
var numWordsPerLine = 4;
var str = [];
for (var word in words) {
if (word > 0 && word % numWordsPerLine == 0) {
str.push('<br>');
}
str.push(words[word]);
}
return (str.slice(0, str.length - 2)).join(' ');
},
navigation: {
activeColor: '#3E576F',
animation: true,
arrowSize: 12,
inactiveColor: '#CCC',
useHTML: true,
style: {
fontWeight: 'bold',
color: '#333',
fontSize: '12px'
}
}
},
series: [{
name: 'Brands',
colorByPoint: true,
data: dataArray
}]
});

附上下面的两个屏幕

1. 预期 - 初始加载饼图
Expected and initially loaded pie chart

2. 宽度减小 - 在按钮点击时加载
Width reduced

顺便说一句,我有两个 div,一个有几个过滤器和一个提交按钮,另一个是显示的图表。当我需要显示基于过滤器的图表并显示在 ajax 响应上时,我还隐藏了显示图表的 div。

JSFIDDLE

提前致谢。

最佳答案

问题在于隐藏 <div> .我用 jQuery 的 hide() 隐藏了 div功能

请为 Why are Bootstrap tabs displaying tab-pane divs with incorrect widths when using highcharts? 找到类似的答案

关于android - Highcharts (PieChart) - 第二次绘制时图表宽度减小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38789284/

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