question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Chart.js + Boostrap panel

See original GitHub issue

Hello,

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:closed
  • Created 9 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
Teddy95commented, Jan 2, 2015

I’ve solved the problem:

Use this code:

<div class="panel-body">
    <div>
        <canvas id="myChart"></canvas>
    </div>
</div>

Instead of this:

<div class="panel-body">
    <canvas id="myChart"></canvas>
</div>
0reactions
fulldecentcommented, Jan 19, 2015

Duplicate #507

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found