No x-axis pan or zoom using Chart.js 2.6.0
chartjs-plugin-zoom seems to have some problems in conjunction with Chart.js 2.6.0: In my case, I cannot pan or zoom on the x-axis.
When I simply run npm install [email protected] x-axis panning and zooming starts working again immediately. Running npm install [email protected] breaks x-axis pan&zoom again. So it looks like a problem with the chart.js version.
Are you experiencing the same problems or is this working for you? Any ideas what I can do to upgrade to the latest version of chartjs-plugin-zoom (it has 2.6.0 as dependency)? Please help.
In my config I use:
pan: {
enabled: true,
mode: 'xy',
rangeMin: {
x: null,
y: null
},
rangeMax: {
x: null,
y: null
}
},
zoom: {
enabled: true,
mode: 'xy',
}
Enviroment:
- Ionic 3.5.3
- ng2-charts 1.6.0
Edit: Chart-type: time
+1 having exactly the same problem. Even the chart in the live codepen demo link doesn't work on zooming. I would like to go to chart.js 2.5.0 but I am worried I will have to change my app code and also might be missing some features by downgrading to chart.js 2.5.0
i have chartjs 2.6 zoom is working fine on x-axis. But panning of x-axis (simple x-axis which is by default category axis) is not supported. Whether it is 2.5 or any version. You can see this library main page in to do list.
My chart is a timeline series (x axis is date-time) line chart also utilizing chartjs-plugin-zoom and hammer.js. Neither zoom nor pan works for chart.js 2.6. As soon as I tried @meisterlampe 's idea using chart.js 2.5 without changing any line of my code, both pan and zoom started working. Weird...
weird! i have not experienced this in my time axis.
I too have a time series with moment.js-datetime-objects on the x-Axis (will add this info to my original post, maybe it's important).
yeah may be, may be you should stick 2.5 chart.
zoom-time.html in the samples-folder is a good example:
Running npm install after a fresh clone of this repo gets you chart.js 2.6.0 and drag-zooming is not working in this sample, when I open it in chromium 59.
Now just change line 7 in zoom-time.html:
Change:
<script src="../node_modules/chart.js/dist/Chart.js"></script>
to this:
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.5.0/Chart.min.js"></script>
In my case drag-zooming is working again after this minor change.. I tried to debug and found out that the function zoomTimeScale isn't called at all, when using chart.js 2.6.0. But I have no idea why.. ..maybe I'm testing the wrong way. Any ideas much appreciated..
Having the same problem here, using timeaxis and zooming works when using chartjs 2.5 but not for 2.6. Nothing else is changed in the code.
I had the same problem with time x axis. After some investigation, it seems that firstTick and lastTick is no longer available on the ChartElement object. Instead, the pan function for time needs to manually index into the ticks array to get both firstTick and lastTick. I am working on a patch, and will test if this solves the problems for 2.6.0.
How'd you go @hilljh82 ?
@hilljh82 very nice tips! for a quick fix, since there are no more firstTick and lastTicks, how about instead to use scale.min and scale.max? although my tick unit doesn't seem to zoom in (only zoom out)
Also hoping for a solution on this. ChartJS is already at 2.7.0 now. Maybe @hilljh82 can get it to work.
Thanks to @hilljh82 and @NujiaLin for pinpointing the issue, I believe pull request #105 will fix this (worked for me) - just as mentioned, the tick units don't increase update when zooming in.
Also, figured out why the axis ticks were not updating when zooming in - the ticks are being built before the options.time.min and max are taken into account.
Editing the release build of Chart.js "buildTicks" (line ~13844) function to move the following lines:
// Enforce limits with user min/max options
min = parse(timeOpts.min, me) || min;
max = parse(timeOpts.max, me) || max;
Just after this one:
var timeOpts = options.time;
Then the ticks update as you would expect.
@jarrodbell Thanks!! this will save me a great deal of time 😄
@jarrodbell Thanks for your PR! I'm having some problems getting this to work, but pretty sure something collides with my other PRs, that haven't been merged yet into this project. :-D I'll have a look into that later.. Is your fix for the buildTicks for 2.6.0 or 2.7.0?
I am using 2.7.0
Ah ok.. now I got it to work. Thanks :)
Hi guys, anyone with some link or example integration of chat.js + chartjs-plugin-zoom for Ionic. I tried in every possible way and I can not use chartjs-plugin-zoom.
I don't seem to be able to get chartjs-plugin-zoom (v0.5.0) to work with chart.js (v2.7.0), these two lines in chartjs-plugin-zoom.js always end up with invalid date:
options.time.min = rangeMinLimiter(zoomOptions, scale.getValueForPixel(scale.getPixelForValue(scale.firstTick) + minDelta));
options.time.max = rangeMaxLimiter(zoomOptions, scale.getValueForPixel(scale.getPixelForValue(scale.lastTick) - maxDelta));
Any ideas about what I'm doing wrong? Here is my chart options:
var chartOptions = {
scales: {
xAxes: [{
type: 'time',
time: {
displayFormats: {
minute: 'Y-MM-DD LTS',
hour: 'Y-MM-DD LTS',
day: 'Y-MM-DD',
week: 'Y-MM-DD',
month: 'MMM Y'
},
minUnit: 'minute',
tooltipFormat: 'Y-MM-DD LTS'
},
ticks: {
callback: function (arg) {
var matches = arg.match(/([0-9-]{10})(.*)/);
if (matches) {
return [matches[1], matches[2]];
}
return arg;
},
minRotation: 0,
maxRotation: 0
}
}],
yAxes: []
},
animation: {
duration: 0
},
legend: {
position: 'top',
labels: {
usePointStyle: true
}
},
maintainAspectRatio: false,
zoom: {
enabled: true,
mode: 'x'
},
pan: {
enabled: true,
mode: 'x'
},
elements: {
line: { tension: 0 }
}
};
I'm inserting moment objects in to the time axes. The chart works fine but breaks if I try to zoom.
If I change charjs version to 2.5.0 and chartjs-plugin-zoom version to 0.4.5 the zoom works.