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

minRange for Category

Open mBreyerBG opened this issue 1 year ago • 3 comments

I have a barChart with categories. i am using drag to zoom. How can i define a minimum amount of categories, just like e.g: limits.x.minRange would work? Is this possible?! Right now i can zoom, so that only one category is visible and fills the whole chart. i want like minimum of 4 categories to be visible

mBreyerBG avatar Nov 08 '23 13:11 mBreyerBG

+1

jgrayson-apl avatar Jan 11 '24 17:01 jgrayson-apl

+1

There is supposed to be a prop for this but nothing worked. You can try this as a workaround:

           const minDesiredElems = 10;
           onZoomStart: ({ event, chart }) => {
            const isZoomIn = event.deltaY < 0;
            const hasLessThanDesired = chart.scales.xAxes.ticks?.length <= minDesiredElems;
            // reset it back in case of a big step
            if (chart.scales.xAxes.ticks?.length <= minDesiredElems-1 && isZoomIn) {
              chart.zoom(chart, { x: minDesiredElems });
            }
            // skip zoom event
            if (isZoomIn && hasLessThanDesired) return false;
          }

(This isn't really well tested code, but somewhat works)

alimertcakar avatar Apr 24 '24 07:04 alimertcakar

+1

fecipo avatar May 13 '24 12:05 fecipo