Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

height changed unexpectedly after re-rendering #178

Closed
giantwhale opened this issue Aug 23, 2017 · 2 comments
Closed

height changed unexpectedly after re-rendering #178

giantwhale opened this issue Aug 23, 2017 · 2 comments

Comments

@giantwhale
Copy link

I set width and height both to 300 and I am refresing my chart every 10 seconds. At first the charts are properly sized, however, after the first refresh, the chart size changes. I tried many different combinations by setting responsive and maintainAspectRatio, but in some cases width changes from 300->700 after refreshing, and in other cases height changes from 300->700

My Code:

In the template I have:

        <section v-for='dataitem in lineChartData'>
            <div class='mainchart'>
                <LineChart :width="800" :height="300" 
                           :chartData="dataitem" :chartOption="chartopt"></LineChart>
            </div>
        </section>

And the javascript is :

const $ = require('jquery');
import LineChart from "./line_chart";

export default {
  name: 'app'
  , data () {
        return { 
        , 'lineChartData': []
        , 'chartopt': {
            responsive: false, 
            maintainAspectRatio: false,
            elements: { 
                point: { radius: 0 } 
            }, 
            scales: {
                xAxes: [{
                    ticks: {
                        autoSkip: true,
                        maxTicksLimit: 26
                    }
                }]
            }
        }
        , 'interval10': null
        }
    }
    , components: {
        LineChart
    }
    , methods: {
        load_data() {
            var self = this;
            $.getJSON("http://localhost:8001/data", function(json) {
                let data = $.extend({}, json);
                self.lineChartData = data.Accounts;  // i am only assigning a member to lineChartData, which is a list of datasets, label pairs.
            });
        }

    }
    , mounted() {
        var self = this;

        this.load_data(); 
        
        this.interval10 = setInterval(() => {
            this.load_data();
        }, 10000)
    }
    ,  beforeDestroy: function(){
        clearInterval(this.interval10);
    }
}

Then the actual chart component js:

import VueChartJs from 'vue-chartjs';
import { Line } from 'vue-chartjs';

export default Line.extend({
      props: ['chartOption']
    , mixins: [VueChartJs.mixins.reactiveProp]
    , mounted () {
        this.renderChart(this.chartData, this.chartOption)
    }
})
@apertureless
Copy link
Owner

apertureless commented Aug 23, 2017

Try naming your options prop options and not chartOption .
Because the reactive mixin will call a re-render if nessasary and is calling this.renderChart(this.chartData, this.options)

And please provide a minimal codepen for reproduction.

@apertureless
Copy link
Owner

closed due to inactivity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants