Chart.js + Boostrap panel
See original GitHub issueHello,
I’m having some difficulty displaying a chart inside a Bootstrap panel. If I place a basic line chart alone it works fine:
<canvas id="memoryTrendChart" width="100" height="50"></canvas>
var lineChartData = {
labels: ['', '', '', ''],
datasets: [{
label: "Memory Usage",
fillColor: "rgba(151,187,205,0.2)",
strokeColor: "rgba(151,187,205,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: [13, 56, 45, 34]
}, {
label: "Base Usage",
fillColor: "rgba(246,150,121,0.2)",
strokeColor: "rgba(242,108,079,1)",
pointColor: "rgba(151,187,205,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(151,187,205,1)",
data: [15, 18, 35, 66]
}]
}
//Get the context of the canvas element we want to select
var ctx = $("#memoryTrendChart").get(0).getContext("2d");
// This will get the first returned node in the jQuery collection.
var myNewChart = new Chart(ctx).Line(lineChartData, {
animationSteps: 15,
bezierCurve: false,
pointDot: false,
showScale: false,
scaleShowLabels: false,
showTooltips: false,
tooltipTemplate: "<%if (label){%><%=label%> (<%}%><%= value %> MB)",
responsive: true
});
However, placing it within a Bootstrap panel doesn’t work as I would expect. The chart will not be displayed:
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title">Memory Trend</h3>
</div>
<div class="panel-body">
<canvas id="memoryTrendChart" width="100" height="50"></canvas>
</div>
</div>
Also, I noticed that it’s very difficult to get the width/height right even when in “standalone” mode. Looks like with larger values it works fine, but with smaller ones it does not (i.e. {width: 100, height: 50}
) The documentation implies that the dimensions should be placed in the <canvas> tag, but I’m not having much luck with it.
What am I missing? Thanks!
Issue Analytics
- State:
- Created 9 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
javascript - Chartjs line graph goes over panel - Stack Overflow
I am currently using chartjs for graphs and I want to be able to display these in a bootstrap panel. I have managed...
Read more >Charting with Bootstrap, Chartjs - CodePen
Trying out chart.js as a designer.... ... <h2>Charting with Chartjs</h2> ... <div class="panel-footer">A simple Line Chart with basic settings</div>.
Read more >ChartJS | Bootstrap Based Admin Template - Material Design
ChartJS Taken from github.com/chartjs/Chart.js · LINE CHART · BAR CHART · RADAR CHART · PIE CHART.
Read more >Bootstrap Charts Guideline - examples & tutorial
Bootstrap charts are graphical representations of data. Charts come in different sizes and shapes: bar, line, pie, radar, polar and more.
Read more >Column Chart within Bootstrap Panel - CanvasJS ... - JSFiddle
Test your JavaScript, CSS, HTML or CoffeeScript online with JSFiddle code editor.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve solved the problem:
Use this code:
Instead of this:
Duplicate #507