Jquery CanvasJS旋转木马无法在引导4上工作
我想画图表并在上面应用旋转木马。我用的是画布。但我没有得到任何输出。我看不到任何图表。我使用的是Bootstrap4.1.3Jquery CanvasJS旋转木马无法在引导4上工作,jquery,html,charts,bootstrap-4,canvasjs,Jquery,Html,Charts,Bootstrap 4,Canvasjs,我想画图表并在上面应用旋转木马。我用的是画布。但我没有得到任何输出。我看不到任何图表。我使用的是Bootstrap4.1.3 <!-- Indicators --> <ul class="carousel-indicators"> <li data-target="#demo" data-slide-to="0" class="active"></li> <li da
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
在此之前,我曾尝试使用谷歌图表,但我不知道如何在它们上应用旋转木马。我想要多个图表和旋转木马连成一行。我在谷歌图表上找不到任何与应用旋转木马相关的东西,所以我切换到CanvasJS,但没有任何效果
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
请用CanvasJS或谷歌图表帮助我
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
下面是我的CanvasJS代码:
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
CSS:
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
HTML和JS/JQuery:
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
首先确保你的引导转盘工作正常
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
这是基于引导文档的,从这里开始:
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
我包括了最新版本的jQuery和用于Bootstrap4的CDN
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
我还使用了来自的占位符图像
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
您可以在引导转盘中呈现图表。看看这个或者找到下面的代码
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#demo" data-slide-to="0" class="active"></li>
<li data-target="#demo" data-slide-to="1"></li>
<li data-target="#demo" data-slide-to="2"></li>
</ul>
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="carousel-item active">
<div id="chartContainer1" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer2" class="chart" style="width:100%;
height:360px;"></div>
</div>
<div class="carousel-item">
<div id="chartContainer3" class="chart" style="width:100%;
height:360px;"></div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#demo" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
<script>
var chart;
var charts = [];
var width;
var height;
width = $('#demo').width();
height = $('#demo').height();
$('.carousel').carousel({
interval: false,
});
chart = new CanvasJS.Chart("chartContainer1", {
title: {
text: "Column Chart"
},
width: width,
height: height,
data: [{
type: "column",
dataPoints: [{
x: 10,
y: 171
}, {
x: 20,
y: 155
}, {
x: 30,
y: 150
}, {
x: 40,
y: 165
}, {
x: 50,
y: 195
}, {
x: 60,
y: 168
}, {
x: 70,
y: 128
}, {
x: 80,
y: 134
}, {
x: 90,
y: 114
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer2", {
title: {
text: "Line Chart"
},
width: width,
height: height,
data: [{
type: "line",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
chart = new CanvasJS.Chart("chartContainer3", {
title: {
text: "Area Chart"
},
width: width,
height: height,
data: [{
type: "area",
dataPoints: [{
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
}]
}]
});
chart.render();
charts.push(chart);
$(window).resize(function() {
for (var i = 0; i < charts.length; i++) {
charts[i].options.width = $('.carousel').width();
charts[i].options.height = $('.carousel').height();
charts[i].render();
}
});
</script>
var图表=[];
var dps=[
{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}
];
$'.carousel'.carousel{
间隔时间:2000年
};
$'.carousel'。在“slide.bs.carousel”上,函数e{
$.carousel-inner.heightparseFloatcharts[e.to].container.style.height;
};
$'.carousel'。在'slided.bs.carousel'上,函数e{
图表[e.to].渲染;
};
var chart1=new CanvasJS.chartContainer1{
标题:{
文字:柱状图
},
数据:[{
类型:列,
数据点:dps
}]
};
图表1.渲染;
图表1;
var chart2=新CanvasJS.chartcontainer2{
标题:{
文本:样条曲线图
},
数据:[{
类型:花键,
数据点:dps
}]
};
图表2;
var chart3=新CanvasJS.chartContainer3{
标题:{
文本:面积图
},
数据:[{
类型:区域,
数据点:dps
}]
};
图表3;