0

I have tried so many things (modify css, add inline css to canvas, add inline css to a wrapper div of canvas) but I still can't make the chart fit in the panel properly.

enter image description here

Here is the HTML

        <section class="panel">
            <header class="panel-heading">
                Temp
            </header>
                <canvas id="tempChart"></canvas>
        </section>

Here is the js code

<script>

var data = {
    labels: ["January", "Aary", "March", "April", "May", "June"],
    datasets: [{
        label: "My First dataset",
        fillColor: 'rgba(220,220,220,0)',
        strokeColor: "rgba(220,220,220,1)",
        pointColor: 'red',
        pointStrokeColor: "#fff",
        pointHighlightFill: "#fff",
        pointHighlightStroke: "rgba(220,220,220,1)",
        data: [65, 59, 80, 81, 56, 55, 40]
    } ]
};

var option = {
    responsive: true,

};

var ctx = $("#tempChart").get(0).getContext("2d");
var myLineChart = new Chart(ctx).Line(data, option);

The class panel in CSS contains only graphic things such as border background color and so on. By the way I am using Bootstrap grid. Thanks for your help.

4
  • can you add a jsfiddle.net ? Commented Jun 8, 2017 at 21:13
  • have you tried to set all your charts responsive with default value : Chart.defaults.global.responsive = true; Commented Jun 8, 2017 at 21:14
  • Is this v1 of chartjs? Commented Jun 8, 2017 at 21:15
  • Have you tried ctx.height and ctx.width propert? like: ctx.height = 20; ctx.width = 80; It will set width and height for your canvas element. Commented Jun 9, 2017 at 6:25

2 Answers 2

0

have you tried to set all your charts responsive with default value : Chart.defaults.global.responsive = true;

Your global synthax seems correct has you setted up

var options = { responsive:true }

However; it's a tiny detail but you added a coma after that true. I suggest to remove it.

as @brian suggested; please; inform us the version of the lib. Add a jsfindle is even better

Sign up to request clarification or add additional context in comments.

Comments

0

Thanks for all the replies. The problem was the version of lib I was using. Updating that solved the problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.