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

overlapped values in Stacked bar(xAxes + yAxes) #7716

Closed
Roman991 opened this issue Aug 18, 2020 · 7 comments
Closed

overlapped values in Stacked bar(xAxes + yAxes) #7716

Roman991 opened this issue Aug 18, 2020 · 7 comments

Comments

@Roman991
Copy link

Roman991 commented Aug 18, 2020

Expected Behavior

Every bar shoud start at y = 0 and all bars (one per day) shoud have data appended
<----data1-----><--------data2---------><-------data3------> (vertical in the example)

Current Behavior

in this case u can see that bars are not continuous

Possible Solution

I also tried to fill all dates with y:0 and to change x to js Date Object and ISOString

Steps to Reproduce

link to reproduce
stack blitz

Context

Environment

  • Chart.js version:
  • Browser name and version:
  • Link to your project:
@kurkle
Copy link
Member

kurkle commented Aug 18, 2020

v2 uses index based stacking. v3 stack by value, so should work with chart.js@next

@Roman991
Copy link
Author

it did the job, but it was a pain.

In angular's scope it was complaining about:

core.js:4197 ERROR Error: "category" is not a registered scale.
    at Registry._get (chart.esm.js:4347)
    at Registry.getScale (chart.esm.js:4313)
    at chart.esm.js:4739
    at each (core.js:49)
    at Chart.buildOrUpdateScales (chart.esm.js:4726)
    at Chart.update (chart.esm.js:4842)
    at new Chart (chart.esm.js:4633)
    at SafeSubscriber._next (stats-inserimenti.component.ts:102)
    at SafeSubscriber.__tryOrUnsub (Subscriber.js:183)
    at SafeSubscriber.next (Subscriber.js:122)

btw I found an ugly workaround to make it work, changing the scope to global
this.chart = new window.Chart(this.statsInserimento.nativeElement, this.config);

it's still an alpha so idk if u want to investigate

@kurkle
Copy link
Member

kurkle commented Aug 19, 2020

@Roman991
Copy link
Author

I had to register manually all elements

import { Chart, LineController,Line, Point, LinearScale, CategoryScale, Title, Tooltip, Filler, Legend, BarController, Rectangle,} from 'chart.js';
Chart.register( LineController, Line, Point, LinearScale, CategoryScale, Title, Tooltip, Filler, Legend, BarController, Rectangle);

isn't it a bit tricky?

I had to inspect the dist file to find that type:'bar'needs the BarController and Rectangle to work.

btw THANK you!

here a working example
STACKBLITZ
...actually it's not working in stackbliz environment (async import?)

@kurkle
Copy link
Member

kurkle commented Aug 21, 2020

I had to register manually all elements
isn't it a bit tricky?

It is, but thats the only way we could make tree shaking work while still using strings for type of dataset / scale / dataElementType / datasetElementType. More about that there: #7371

@23subbhashit
Copy link

try this:

xAxes: [{ stacked: true }],
  yAxes: [{
    stacked: false,
    ticks: {
      beginAtZero: true,
    },
  }]

@kurkle
Copy link
Member

kurkle commented Aug 24, 2020

closing as resolved

@kurkle kurkle closed this as completed Aug 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants