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

Zoom And Pan Options in Vue Charts #94

Closed
arunrreddy opened this issue Apr 28, 2017 · 11 comments
Closed

Zoom And Pan Options in Vue Charts #94

arunrreddy opened this issue Apr 28, 2017 · 11 comments

Comments

@arunrreddy
Copy link

This would be a handy enhancement. There is a repo called which does exactly this - chartjs-plugin-zoom.js(https://github.com/chartjs/chartjs-plugin-zoom).
This feature would be good if it was integrated for Vue for both the axes of a chart.

@apertureless
Copy link
Owner

apertureless commented Apr 28, 2017

Hey @arunrreddy !

Well, vue-chart.js is only a wrapper for Chart.js
So functions like this would be rather an imporvement for chart.js as for this repo.

However as we are using Chart.js under the hood, you can use any chart.js plugins available! So you can also use the chartjs-plugin-zoom and mostly any other plugin from the chart.js eco-system :)

@arunrreddy
Copy link
Author

arunrreddy commented Apr 28, 2017 via email

@apertureless
Copy link
Owner

Well for me its working 🙈

https://codepen.io/apertureless/full/KmWmKp/

@lionel-bijaoui
Copy link

lionel-bijaoui commented Jul 27, 2017

Here is an example of incorporation into a webpack project.
Very basic example from the quick start:

// CommitChart.js
import { Bar } from 'vue-chartjs'
import zoom from 'chartjs-plugin-zoom';

export default Bar.extend({
  mounted () {
    this.addPlugin(zoom);
    // Overwriting base render method with actual data.
    this.renderChart(data, options)
  }
})

Very basic example with reactive data from the doc:

import { Line, mixins } from 'vue-chartjs';
import zoom from 'chartjs-plugin-zoom';
const { reactiveProp } = mixins;

export default Line.extend({
    mixins: [reactiveProp],
    props: ['options'],
    mounted() {
        this.addPlugin(zoom);
        // this.chartData is created in the mixin
        this.renderChart(this.chartData, this.options);
    }
});

Don't forget to add the options !

@vlad909
Copy link

vlad909 commented Oct 4, 2018

@lionel-bijaoui, tnx very much :)

@ppirrip
Copy link

ppirrip commented Oct 23, 2018

hi, chartjs-plugin-zoom works well with my vue-chart.js setup, however, I have some problem with resetting the zoom (resetZoom()). From the example, I need to access to the chart object (window.myLine = new Chart(ctx, config)) to access the function (e.g. window.myLine.resetZoom()), but I have no idea how. Anyone encounter this before?

@ppirrip
Copy link

ppirrip commented Oct 23, 2018

Got it! Should have read the doc more carefully before I ask. This works for me: this.$data._chart.resetZoom();

@nauhalf
Copy link

nauhalf commented Nov 2, 2020

Here is an example of incorporation into a webpack project.
Very basic example from the quick start:

// CommitChart.js
import { Bar } from 'vue-chartjs'
import zoom from 'chartjs-plugin-zoom';

export default Bar.extend({
  mounted () {
    this.addPlugin(zoom);
    // Overwriting base render method with actual data.
    this.renderChart(data, options)
  }
})

Very basic example with reactive data from the doc:

import { Line, mixins } from 'vue-chartjs';
import zoom from 'chartjs-plugin-zoom';
const { reactiveProp } = mixins;

export default Line.extend({
    mixins: [reactiveProp],
    props: ['options'],
    mounted() {
        this.addPlugin(zoom);
        // this.chartData is created in the mixin
        this.renderChart(this.chartData, this.options);
    }
});

Don't forget to add the options !

@lionel-bijaoui I try this method, it works on zoom and pan. But my scale ticks yAxes callback not working. It reset to default after first time zoom.

Before Zoom
image

After Zoom
image

This is my scale ticks callback
scales: { yAxes: [ { ticks: { callback: label => numeral(label).format("0.00 a") //just formatting number with numeral js } } ] }

Is it bug from zoom plugin or vue-chartjs ? Thank you

@ghost
Copy link

ghost commented Nov 19, 2020

I have the same issue as @nauhalf . My options in terms of scales seem to be completely lost after the first interaction with the chart (zoom or pan). I believe this is because the plugin calls the chart update method but doesn't pass the options object defined in the component's data (like we're supposed to do with Vue). Any way to make this work or is it a lost cause?

@nauhalf
Copy link

nauhalf commented Nov 19, 2020

@vbersier After many tried, I found that in only lost the callback on new version library. I change the version of the libraries like this.

vue-chart-js: ^3.5.0
chart.js: ^2.9.3
chartjs-plugin-zoom: ^0.7.7

I hope it works well for you too.

@ghost
Copy link

ghost commented Nov 20, 2020

Thanks @nauhalf , since I could not really wait I implemented my own zoom function with sliders next to the axes but maybe that will help developers figure out what changed.

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

6 participants