我有一个用bootstrap制成的页面,并且在此页面中有2个不同的部分,第一个使用“ col-lg-12”,第二个使用“ col-lg-6”,两者均可拖动。我想在其中放一些弹药,一切正常,我的图表可以响应,但是当我将div中的一个大部分移动到小部分时,图表响应功能停止工作,并且无法自动调整大小。 我的html代码
<script src="https://www.amcharts.com/lib/4/core.js"></script>
<script src="https://www.amcharts.com/lib/4/charts.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/material.js"></script>
<script src="https://www.amcharts.com/lib/4/themes/animated.js"></script>
<div class="row" id="kt_sortable_portlets">
<div class="col-lg-12">
<!--begin::Portlet-->
<div class="kt-portlet kt-portlet--sortable">
<div class="kt-portlet__head">
<div class="kt-portlet__head-label">
<h3 class="kt-portlet__head-title">
Big div
</h3>
</div>
</div>
<div class="kt-portlet__body">
<div id="kt_chart1" style="min-height: 300px;">
</div>
</div>
</div>
<!--end::Portlet-->
<!-- begin:Empty Portlet: sortable porlet required for each columns! -->
<div style="border:5px dashed rgb(54, 161, 233);visibility: visible;text-align: center" class="kt-portlet kt-portlet--sortable-empty">
<h5 style="margin: auto auto">Drag here to Full screen</h5>
</div>
<!--end::Empty Portlet-->
</div>
<div class="col-lg-6">
<!--begin::Portlet-->
<div class="kt-portlet kt-portlet--sortable">
<div class="kt-portlet__head">
<div class="kt-portlet__head-label">
<h3 class="kt-portlet__head-title">
small div
</h3>
</div>
</div>
<div class="kt-portlet__body">
<div id="kt_flotcharts_heart" style="min-height: 300px;">
</div>
</div>
</div>
<!-- begin:Empty Portlet: sortable porlet required for each columns! -->
<div class="kt-portlet kt-portlet--sortable-empty"></div>
</div>
<!--end::Portlet-->
<script>
var KTAppOptions = {"colors":{"state":
{"brand":"#5d78ff","light":"#ffffff","dark":"#282a3c","primary":"#5867dd","success":"#34bfa3","info":"#36a3f7","warning":"#ffb822","danger":"#fd3995"},"base":{"label":["#c5cbe3","#a1a8c3","#3d4465","#3e4466"],"shape":["#f0f3ff","#d9dffa","#afb4d4","#646c9a"]}}};
</script>
我的js代码
// Themes begin
am4core.useTheme(am4themes_material);
am4core.useTheme(am4themes_animated);
// Themes end
var chart = am4core.create("kt_chart1", am4charts.XYChart);
var drawChart=function(){
var data = [];
var open = 100;
var close = 120;
var names = ["Raina",
"Demarcus",
"Carlo",
"Jacinda",
"Richie",
"Antony",
"Amada",
"Idalia",
"Janella",
"Marla",
"Curtis",
"Shellie",
"Meggan",
"Nathanael",
"Jannette",
"Tyrell",
"Sheena",
"Maranda",
"Briana",
"Rosa",
"Rosanne",
"Herman",
"Wayne",
"Shamika",
"Suk",
"Clair",
"Olivia",
"Hans",
"Glennie",
];
for (var i = 0; i < names.length; i++) {
open += Math.round((Math.random() < 0.5 ? 1 : -1) * Math.random() * 5);
close = open + Math.round(Math.random() * 10) + 3;
data.push({ category: names[i], open: open, close: close });
}
chart.data = data;
var categoryAxis = chart.xAxes.push(new am4charts.CategoryAxis());
categoryAxis.renderer.grid.template.location = 0;
categoryAxis.dataFields.category = "category";
categoryAxis.renderer.minGridDistance = 15;
categoryAxis.renderer.grid.template.location = 0.5;
categoryAxis.renderer.grid.template.strokeDasharray = "1,3";
categoryAxis.renderer.labels.template.rotation = -90;
categoryAxis.renderer.labels.template.horizontalCenter = "left";
categoryAxis.renderer.labels.template.location = 0.5;
categoryAxis.renderer.inside = true;
categoryAxis.renderer.labels.template.adapter.add("dx", (dx, target)=>{
return -target.maxRight / 2;
})
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
valueAxis.tooltip.disabled = true;
valueAxis.renderer.ticks.template.disabled = true;
valueAxis.renderer.axisFills.template.disabled = true;
var series = chart.series.push(new am4charts.ColumnSeries());
series.dataFields.categoryX = "category";
series.dataFields.openValueY = "open";
series.dataFields.valueY = "close";
series.tooltipText = "open: {openValueY.value} close: {valueY.value}";
series.sequencedInterpolation = true;
series.fillOpacity = 0;
series.strokeOpacity = 1;
series.columns.template.width = 0.01;
series.tooltip.pointerOrientation = "horizontal";
var openBullet = series.bullets.create(am4charts.CircleBullet);
openBullet.locationY = 1;
var closeBullet = series.bullets.create(am4charts.CircleBullet);
closeBullet.fill = chart.colors.getIndex(4);
closeBullet.stroke = closeBullet.fill;
chart.cursor = new am4charts.XYCursor();
chart.scrollbarX = new am4core.Scrollbar();
chart.scrollbarY = new am4core.Scrollbar();
}
var KTPortletDraggable = function () {
return {
//main function to initiate the module
init: function () {
$("#kt_sortable_portlets").sortable({
connectWith: ".kt-portlet__head",
items: ".kt-portlet",
opacity: 0.8,
handle : '.kt-portlet__head',
coneHelperSize: true,
placeholder: 'kt-portlet--sortable-placeholder',
forcePlaceholderSize: true,
tolerance: "pointer",
helper: "clone",
tolerance: "pointer",
forcePlaceholderSize: !0,
helper: "clone",
cancel: ".kt-portlet--sortable-empty", // cancel dragging if portlet is in fullscreen mode
revert: 250, // animation in milliseconds
update: function(b, c) {
if (c.item.prev().hasClass("kt-portlet--sortable-empty")) {
c.item.prev().before(c.item);
}
}
});
}
};
}();
jQuery(document).ready(function() {
drawChart();
KTPortletDraggable.init();
});
这是我的完整代码: https://jsfiddle.net/primemb/va0n4xs3/6/
答案 0 :(得分:1)
我尚不清楚到底是什么导致图表无法调整大小。
当您开始拖动大div时,图表的父级的父级div(.kt-portlet
)将得到display: none;
。停止拖动后,它将重新设置为flexbox,并且图表不再自动调整大小(尝试通过devtools手动更新#kt_chart1
的宽度)。
但是,如果您手动将图表div的父项(.kt-portlet__body
)或父项的父项的显示模式重置为display: block;
,然后不久将其删除,则图表可以再次自动调整大小。
因此,要使此功能再次正常运行(希望不会引发不正确的样式错误内容闪烁)的一种怪诞方法,是在stop
event of the slider
之后的短时间内执行上述操作:
stop: function(event, ui) {
setTimeout(function() {
ui.item.css('display', 'block');
}, 10);
setTimeout(function() {
ui.item.css('display', '');
}, 20);
},
叉子: https://jsfiddle.net/notacouch/w5qjpcs1/3/
顺便说一句,这是[y]我们GitHub问题的重复: