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

Zooming a category axis with the mouse wheel barely works #360

Closed
yoelz55 opened this issue May 25, 2020 · 5 comments · Fixed by #476
Closed

Zooming a category axis with the mouse wheel barely works #360

yoelz55 opened this issue May 25, 2020 · 5 comments · Fixed by #476
Labels

Comments

@yoelz55
Copy link

yoelz55 commented May 25, 2020

Hi there,

  • What version of the plugin and chart.js?
    Chartjs: 2.9.3
    Zoom: 0.7.7

The zoom on the y-axis works perfectly.
The x-axis doesn't work at all when the mouse cursor while zooming is on the left side, and when the cursor is on the right side, it does the zoom but really really slow (even when changing the speed and sensitivity) .

I tried also the functionality of zoom by dragging, unfortunately, I got the same result, the x-axis didn't work but the y-axis worked fine.

Please check out this example:
https://codepen.io/yoelz55/pen/WNQLxRN

Thank you in advance for any help,
Yoel

Originally posted by @yoelz55 in #50 (comment)

@borjaseijo
Copy link

borjaseijo commented Jun 3, 2020

I have obtained the same issue but using date scale in the x-axis. I have used the following library versions:

  • Chartjs: 2.9.3
  • Hammer.JS: 2.0.7
  • Zoom: 0.7.7

@DjovDev
Copy link

DjovDev commented Jun 18, 2020

I resolved this with changing the type of X-axis to "time". In my case I had the "time" on the X-axis as well so it came out fine. Here is the piece of code defining my X-axes:

My X-data is populated with Moment (momentjs) objects.

xAxes: [{
type: "time",
time: {
format: 'HH:mm',
unit: 'minute'
}
}]

@silasrm
Copy link

silasrm commented Apr 13, 2021

Any solution? My data has a incremental X value, not a datetime. Zoom plugin doesn't work on X axis.
image

@silasrm
Copy link

silasrm commented Apr 14, 2021

Any solution? My data has a incremental X value, not a datetime. Zoom plugin doesn't work on X axis.
image

My solution is using seconds based on length of my data:

const ms = allTradesFull.length;
const startDate = moment().subtract(ms, 'second');

// chartjs config:
const config = {
  //...
  labels: allTradesFull.map((item, k) => moment(startDate).add(k + 1, 'second').toString()),
  //....
  // scales config:
  xAxes: [{
      type: "time",
      time: {
          unit: 'second',
      },
      display: false,
      scaleLabel: {
          display: true,
          labelString: 'Trade #'
      },
      ticks: {
          beginAtZero: true,
          maxRotation: 0,
      },
  }],
  // tooltip config:
  tooltips: {
      mode: 'index',
      intersect: false,
      callbacks: {
          title: function (tooltipItem) {
              return (typeof allTradesFull[tooltipItem[0].index] === 'object' && allTradesFull[tooltipItem[0].index] ? allTradesFull[tooltipItem[0].index].x : null);
          },
          label: function (tooltipItem) {
              return `${currency(tooltipItem.value, '', 2, {thousandsSeparator: '.', decimalSeparator: ','})}`;
          }
      }
  },
};

This is the result:
image

@etimberg etimberg added the bug label Apr 25, 2021
@etimberg etimberg changed the title Zoom in x-axis doesn't work Zooming a category axis with the mouse wheel barely works Apr 25, 2021
@kurkle
Copy link
Member

kurkle commented Apr 27, 2021

Zoom seems to work fine (except not zooming to the actual mouse position) with 1.0.0-beta.3, but pan does not work correctly (because of skipped labels):
https://codepen.io/kurkle/pen/JjEVWZx

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

Successfully merging a pull request may close this issue.

6 participants