我有一个用引导程序制作的页面,我在这个页面中有两个不同的部分,第一个使用“col-lg-12”,第二个使用“col-lg-6”,它们都是可拖动的。我想在其中放一些 amcharts 一切正常,我的图表是响应式的,但是当我将大部分中的 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();
});