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

circumference option in 'chart.options' is undefined #8531

Closed
stockiNail opened this issue Feb 26, 2021 · 10 comments · Fixed by #8534
Closed

circumference option in 'chart.options' is undefined #8531

stockiNail opened this issue Feb 26, 2021 · 10 comments · Fixed by #8534

Comments

@stockiNail
Copy link
Contributor

I don't know if this a bug or I misunderstood the documentation.

The pie/doughnut charts have got some specific options, like , circumference.

From documentation the circumference has got a default of 360 and I'm expecting that when I'm invoking chart.options.circumference I'll get 360 if I didn't set it in the configuration of chart:

var myChart = new Chart(ctx, {
    type: 'pie',
    data: {
      labels: ["Jan", "Feb", "Mar"],
      datasets: [{
        label: 'dataset',
        data: [51, 23, 24],
        backgroundColor: 'lightGrey'
      }]
   },
});
console.log(myChart.options.circumference); // <- my expectation is to see 360. Unfortunately is undefined.

https://codepen.io/stockinail/pen/RwoxzNZ

It's not clear to me where I'm wrong.

@LeeLenaleee
Copy link
Collaborator

According to the docs its set in the dataset options so you will have to go into the data prop instead of the options, also the default value is undefined so you wont get 360 back if it is not being overriden

https://codepen.io/leelenaleee/pen/BaQYrVq

@stockiNail
Copy link
Contributor Author

@LeeLenaleee I'm not sure because if you go here https://www.chartjs.org/docs/master/charts/doughnut#config-options it's clearly reported:

Config Options

These are the customisation options specific to Pie & Doughnut charts. These options are merged with the global chart configuration options, and form the options of the chart.

Name Type Default Description
cutout number|string 50% - for doughnut, 0 - for pie The portion of the chart that is cut out of the middle. If string and ending with '%', percentage of the chart radius. number is considered to be pixels.
radius number|string 100% The outer radius of the chart. If string and ending with '%', percentage of the maximum radius. number is considered to be pixels.
rotation number 0 Starting angle to draw arcs from.
circumference number 360 Sweep to allow arcs to cover.
animation.animateRotate boolean true If true, the chart will animate in with a rotation animation. This property is in the options.animation object.
animation.animateScale boolean false If true, will animate scaling the chart from the center outwards.

This was taken from master. Therefore I don't understand if the doc is outdated or if there is bug.

@kurkle
Copy link
Member

kurkle commented Feb 26, 2021

The radial chart options might be a bit misleading.
console.log(myChart.getDatasetMeta(0).controller.options.circumference); gives you 360.

@LeeLenaleee
Copy link
Collaborator

Was looking at the wrong part of documentation: https://www.chartjs.org/docs/master/charts/doughnut/#dataset-properties

When I override the circumfrence in the options it shows so it looks like it tries to read the option before it got merged
https://codepen.io/leelenaleee/pen/RwoQMOJ

@kurkle
Copy link
Member

kurkle commented Feb 26, 2021

The options aren't actually merged anymore, but looked up on access. So the wording might also be misleading.

@stockiNail
Copy link
Contributor Author

That means some defaults are not reachable anymore and they must be hard coded from users.
Fyi I am talking about the labels plugin.

@stockiNail
Copy link
Contributor Author

stockiNail commented Feb 26, 2021

Or better the fallback logic must be implemented by users and not by proxy.

@kurkle
Copy link
Member

kurkle commented Feb 26, 2021

https://www.chartjs.org/docs/master/general/options#chart-level-options

Looks like the datasets scope is not read, that is the reason for it being undefined.

@stockiNail
Copy link
Contributor Author

@kurkle thank you very much.
But it's not clear if you meant this will be implemented or if it's an architectural decision therefore I have to take care.
For my current use case it's just a "if" statement to add.

@stockiNail
Copy link
Contributor Author

Ok... ignore my previous post.
You marked as bug therefore the answer is clear.

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.

3 participants