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

Legend position: 'chartArea' broken since v3.4.0 (works on 3.3.0) #9914

Closed
volfasengelman opened this issue Nov 28, 2021 · 3 comments · Fixed by #9915
Closed

Legend position: 'chartArea' broken since v3.4.0 (works on 3.3.0) #9914

volfasengelman opened this issue Nov 28, 2021 · 3 comments · Fixed by #9915

Comments

@volfasengelman
Copy link

volfasengelman commented Nov 28, 2021

Expected Behavior

Chart loaded with Legend drawn on chart area, see fiddle - version 3.3.0

Current Behavior

Chart is not loaded, error in console.

Error can be reproduced in this fiddle

chart.esm.js:7584 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'top')
    at Legend.setDimensions (chart.esm.js:7584)
    at Legend.update (chart.esm.js:7573)
    at eval (chart.esm.js:3038)
    at each (helpers.segment.js:224)
    at Object.update (chart.esm.js:3035)
    at Chart._updateLayout (chart.esm.js:5654)
    at Chart.update (chart.esm.js:5636)
    at Chart.eval (chart.esm.js:5390)
    at Chart.eval [as _doResize] (helpers.segment.js:159)
    at Chart._resize (chart.esm.js:5467)
    at Chart.resize (chart.esm.js:5446)
    at attached (chart.esm.js:5933)
    at Chart.bindResponsiveEvents (chart.esm.js:5945)
    at Chart.bindEvents (chart.esm.js:5889)
    at Chart._initialize (chart.esm.js:5432)
    at new Chart (chart.esm.js:5398)
    at ChartjsModule.redraw (chartjsModule.js:222)
    at eval (chart.js:321)

Possible Solution

downgrade or fix bug

Steps to Reproduce

Set Legend position to 'chartArea', as documented here

  options: {
    plugins: {
      legend: {
        position: 'chartArea'
        }
     }
  }

Open fiddle fiddle

Context

I cannot use legend layout 'cartArea'

Environment

  • Chart.js version: 3.6.0
  • Browser name and version: Chrome Version 96.0.4664.45 (Official Build) (64-bit)
  • Link to your project: Open fiddle fiddle
@etimberg etimberg added this to the Version 3.6.1 milestone Nov 28, 2021
@LeeLenaleee
Copy link
Collaborator

It comes from this pr: #9290 the margins are set in the first time it gets passed it but a second time for some reason it gets undefined passed. This breakes it since it cant read top and left from undefined.

Only workaround I can think of is checking is its unefined and if so dont update the margins but I think the issue should be solved in the place where it is getting made undefined

@etimberg
Copy link
Member

I have a possible fix in #9915. Items on the chart area don't have margins, but instead of sending undefined it now sends an object indicating that the margins are 0

@egisz
Copy link

egisz commented Dec 15, 2021

Thanks! I checked and now it works as expected :)

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

Successfully merging a pull request may close this issue.

4 participants