chartjs-plugin-zoom icon indicating copy to clipboard operation
chartjs-plugin-zoom copied to clipboard

Zoom drag doesn't work with x-axis

Open AliBasicCoder opened this issue 6 years ago • 11 comments

hi,

so i when i try to zoom using drag it doesn't work

and i checked if the plugin is loaded and it is

and no messages are printed to the console

and when set mode to xy it only zooms in the y axis

my config

{
    type: "bar",
    data: {
      labels,
      datasets: [
        {
          label: "Download",
          backgroundColor: /* ... */,
          data: /* ... */,
        },
        {
          label: "Upload",
          backgroundColor: /* ... */,
          data: /* ... */,
        },
        {
          label: "Total",
          backgroundColor: /* ... */,
          data: /* ... */,
        },
      ],
    },
    options: {
      legend: {
        display: true,
        position: "right",
      },
      scales: {
        yAxes: [
          {
            ticks: {
              callback: (value: string) => /* ... */,
            },
          },
        ],
      },
      tooltips: {
        callbacks: {
          label(tooltip: { value: string }) {
            /* ... */
          },
        },
      },
      plugins: {
        zoom: {
          zoom: {
            enabled: true,
            drag: true,
            mode: "x",
            onZoom() {
              /* ... */
            },
          },
        },
      },
    },
 };

AliBasicCoder avatar May 12 '20 05:05 AliBasicCoder

Hi, I have exactly the same issue, it seems that there is a problem with the x-axis with numerical type, when I tried the demo of this package, the zoom in x-axis works perfectly because the type of the x-axis is date.

yoelz55 avatar May 12 '20 06:05 yoelz55

I had the same problem, and solved it by upgrading to ChartJS 2.9.1! Try to update if yours is outdated, it might help.

benedekt avatar May 27 '20 11:05 benedekt

I had the same problem, and solved it by upgrading to ChartJS 2.9.1! Try to update if yours is outdated, it might help.

I have tried to solve my issue with this answer, but the zoom problem continues. I think that there is a bug in the plugin.

borjaseijo avatar Jun 03 '20 15:06 borjaseijo

I had the same problem, and solved it by upgrading to ChartJS 2.9.1! Try to update if yours is outdated, it might help.

i tried it with v2.9.1 and v2.9.3 and it didn't work

AliBasicCoder avatar Jun 04 '20 14:06 AliBasicCoder

Hi, I have exactly the same issue, it seems that there is a problem with the x-axis with numerical type, when I tried the demo of this package, the zoom in x-axis works perfectly because the type of the x-axis is date.

You're right. It works when the x-axis is the date. This should be bugs or not support features.

ankworld avatar Jun 05 '20 08:06 ankworld

Yep, I seem to have it this as well on 0.7.7 with date/time x axis (yyy-mm-ddThh:mm:ssZ)

using 0.7.4 will allow the zoom to work

BlueEther avatar Jun 11 '20 05:06 BlueEther

@BlueEther can you test if 0.7.5 or 0.7.6 will work? It'd be nice to narrow down where the regression might have entered

benmccann avatar Jun 11 '20 12:06 benmccann

I have tested with the 0.7.4 and the zoom continues to fail. I am using the following source to generate the final chart where x-axis contains dates that use the format dd-mm-yyyy:

    return new Chart(chart, {
        type: 'line',
        data: {
            labels: labels,
            datasets: [{
                lineTension: 0.3,
                backgroundColor: "rgba(78, 115, 223, 0.05)",
                borderColor: "rgba(78, 115, 223, 1)",
                pointRadius: 3,
                pointBackgroundColor: "rgba(78, 115, 223, 1)",
                pointBorderColor: "rgba(78, 115, 223, 1)",
                pointHoverRadius: 3,
                pointHoverBackgroundColor: "rgba(78, 115, 223, 1)",
                pointHoverBorderColor: "rgba(78, 115, 223, 1)",
                pointHitRadius: 10,
                pointBorderWidth: 2,
                label: labelName,
                data: data
            }]
        },
        options: {
            maintainAspectRatio: false,
            layout: {
                padding: {
                    left: 10,
                    right: 25,
                    top: 25,
                    bottom: 0
                }
            },
            scales: {
                xAxes: [{
                    time: {
                        unit: 'date'
                    },
                    gridLines: {
                        display: false,
                        drawBorder: false
                    },
                    ticks: {
                        maxTicksLimit: 7
                    }
                }],
                yAxes: [{
                    ticks: {
                        maxTicksLimit: 5,
                        padding: 10,
                    },
                    gridLines: {
                        color: "rgb(234, 236, 244)",
                        zeroLineColor: "rgb(234, 236, 244)",
                        drawBorder: false,
                        borderDash: [2],
                        zeroLineBorderDash: [2]
                    }
                }]
            },
            legend: {
                display: false
            },
            tooltips: {
                backgroundColor: "rgb(255,255,255)",
                bodyFontColor: "#858796",
                titleMarginBottom: 10,
                titleFontColor: '#6e707e',
                titleFontSize: 14,
                borderColor: '#dddfeb',
                borderWidth: 1,
                xPadding: 15,
                yPadding: 15,
                displayColors: false,
                intersect: false,
                mode: 'index',
                caretPadding: 10
            },
            plugins: {
                zoom: {
                    // Container for pan options
                    pan: {
                        // Boolean to enable panning
                        enabled: true,
                        mode: 'x'
                    },
                    // Container for zoom options
                    zoom: {
                        enabled: true,
                        drag: {
                         	 animationDuration: 1000
                        },
                        mode: 'x'
                    }
                }
            }
        }
    });

borjaseijo avatar Jun 12 '20 07:06 borjaseijo

I have 1440 points on an X-Acis (24 hours in minutes), all formatted as HH:mm.

I can zoom perfectly on the Y axis, the X-axis does zoom but extremely slow, like 5 minutes per scroll.

DjovDev avatar Jun 17 '20 13:06 DjovDev

I'm also having the same issue on the X axis with lots of datapoints. Drag does not work at all (it zooms, but only sometimes, and never accurately) and scroll zoom is extremely slow no matter what set the speed to.

dmitrygalperin avatar Jul 21 '20 21:07 dmitrygalperin

Closing. We have working samples of drag-to-zoom with different scale types.

kurkle avatar May 16 '21 06:05 kurkle