Javascript Canvas js图表未在模式内加载全宽
我试图使用javascript创建一个模式,但当我在其中添加canvasjs图表时,canvas图表的模式体宽度不是100% 你可以在这张图片中看到我所看到的: 我在javascript中使用以下代码:Javascript Canvas js图表未在模式内加载全宽,javascript,canvasjs,Javascript,Canvasjs,我试图使用javascript创建一个模式,但当我在其中添加canvasjs图表时,canvas图表的模式体宽度不是100% 你可以在这张图片中看到我所看到的: 我在javascript中使用以下代码: // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getEle
// Get the modal
var modal = document.getElementById('myModal');
// Get the button that opens the modal
var btn = document.getElementById("myBtn");
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
}
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
我正试图用javascript实现这一点,我不知道我需要做什么。我想了解为什么会发生这种情况。对您的问题的回答很简单,您在模态显示之前加载图表,需要在加载模态时呈现图表 为了做到这一点,您需要在单击事件中放置图表渲染,如下所示:
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
let chart = new CanvasJS.Chart("chartContainer1", {
animationEnabled: true,
exportEnabled: true,
title: {
text: "Basic Column Chart in Angular"
},
data: [{
type: "column",
dataPoints: [
{ y: 71, label: "Apple" },
{ y: 55, label: "Mango" },
{ y: 50, label: "Orange" },
{ y: 65, label: "Banana" },
{ y: 95, label: "Pineapple" },
{ y: 68, label: "Pears" },
{ y: 28, label: "Grapes" },
{ y: 34, label: "Lychee" },
{ y: 14, label: "Jackfruit" }
]
}]
});
chart.render();
}
这将解决您的问题如果您想知道为什么会发生这种情况,可以将此图表渲染放在以下位置:
modal.style.display = "block";
您将看到图形工作不正常。我希望这能解决您的问题。对您的问题的回答非常简单,您在模态显示之前正在加载图表,您需要在加载模态时呈现图表 为了做到这一点,您需要在单击事件中放置图表渲染,如下所示:
// When the user clicks the button, open the modal
btn.onclick = function() {
modal.style.display = "block";
let chart = new CanvasJS.Chart("chartContainer1", {
animationEnabled: true,
exportEnabled: true,
title: {
text: "Basic Column Chart in Angular"
},
data: [{
type: "column",
dataPoints: [
{ y: 71, label: "Apple" },
{ y: 55, label: "Mango" },
{ y: 50, label: "Orange" },
{ y: 65, label: "Banana" },
{ y: 95, label: "Pineapple" },
{ y: 68, label: "Pears" },
{ y: 28, label: "Grapes" },
{ y: 34, label: "Lychee" },
{ y: 14, label: "Jackfruit" }
]
}]
});
chart.render();
}
这将解决您的问题如果您想知道为什么会发生这种情况,可以将此图表渲染放在以下位置:
modal.style.display = "block";
您将看到图形工作不正常。我希望这能解决您的问题。CanvasJS Chart会根据容器的尺寸自动设置图表的宽度和高度。如果未指定容器的尺寸,它将使用默认的宽度和高度(500px 400px) 在引导中,模式最初不显示,因此图表采用默认的宽度和高度。要解决此问题,应在激发Showed.bs.modal事件时呈现图表
$('#chartModal').on('shown.bs.modal', function () {
chart.render();
});
请在下面查找工作代码:
var chart=new CanvasJS.chart(“chartContainer”{
animationEnabled:没错,
标题:{
正文:“基本柱状图”
},
数据:[
{
键入:“列”,
数据点:[
{x:10,y:71},
{x:20,y:55},
{x:30,y:50},
{x:40,y:65},
{x:50,y:95},
{x:60,y:68},
{x:70,y:28},
{x:80,y:34},
{x:90,y:14}
]
}
]
});
$('#chartmodel').on('show.bs.model',function(){
chart.render();
});代码>
引导模式中的CanvasJS柱形图
开放模态
&时代;
引导模式中的CanvasJS图表
CanvasJS图表根据容器的尺寸自动设置图表的宽度和高度。如果未指定容器的尺寸,它将使用默认的宽度和高度(500px 400px)
在引导中,模式最初不显示,因此图表采用默认的宽度和高度。要解决此问题,应在激发Showed.bs.modal事件时呈现图表
$('#chartModal').on('shown.bs.modal', function () {
chart.render();
});
请在下面查找工作代码:
var chart=new CanvasJS.chart(“chartContainer”{
animationEnabled:没错,
标题:{
正文:“基本柱状图”
},
数据:[
{
键入:“列”,
数据点:[
{x:10,y:71},
{x:20,y:55},
{x:30,y:50},
{x:40,y:65},
{x:50,y:95},
{x:60,y:68},
{x:70,y:28},
{x:80,y:34},
{x:90,y:14}
]
}
]
});
$('#chartmodel').on('show.bs.model',function(){
chart.render();
});代码>
引导模式中的CanvasJS柱形图
开放模态
&时代;
引导模式中的CanvasJS图表
我在文档中看到的是,他们在父div和图表UI中定义了高度和宽度,这与尺寸有关,我建议你试试这个,它会解决问题你是什么意思?我是说在他们的例子中,他们处理宽度和高度,就像我在文档中看到的那样,他们在父div和图表UI中定义了高度和宽度,并尊重这些维度,我建议你试试这个,它会解决问题。你是什么意思?我是说在他们的例子中,他们处理的是宽度和高度之类的东西