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

Donut title doesn't display if datasets are empty initially #227

Closed
sdarnell opened this issue May 10, 2014 · 3 comments
Closed

Donut title doesn't display if datasets are empty initially #227

sdarnell opened this issue May 10, 2014 · 3 comments
Labels
C-bug Category: This is a bug resolved maybe

Comments

@sdarnell
Copy link

I have a donut chart that I populate from a reactive source, and therefore I don't have any data to hand when the initial c3.generate is called. Some time later I add the data.

  var chart = c3.generate({
    size: { width: 300, height: 300 },
    data: {
      columns: [
      ],
      type : 'donut',
    },
    donut: {
      title: "Owner"
    }
  });

I add the data later with:

    chart.load({ columns: _.pairs(_.countBy(issues, 'Owner')) });

The problem seems to be that generation of the title uses:

            // Define g for arc chart area
            main.select('.' + CLASS.chart).append("g")
                .attr("class", CLASS.chartArcs)
                .attr("transform", translate.arc)
              .append('text')
                .attr('class', CLASS.chartArcsTitle)
                .style("text-anchor", "middle")
                .text(getArcTitle());
... with ...
        function getArcTitle() {
            return hasDonutType(c3.data.targets) ? __donut_title : "";
        }

but during init the hasDonutType() returns false because c3.data.targets is empty, and the title doesn't seem to be regenerated when adding data sources.

If this isn't a bug, what is the preferred way to do this lazy initialisation?
I did try having a dummy data source called 'Loading...' which I remove afterwards, but that felt a bit clunky.
I could also keep a separate flag to indicate that I should generate things - but this is also clunky as I would rather keep my data updates completely independent of the chart configuration.

@sdarnell
Copy link
Author

A simple fix seems to be to remove the check:

        function getArcTitle() {
            return __donut_title;
//            return hasDonutType(c3.data.targets) ? __donut_title : "";
        }

The title is hidden when switching to other types of chart, e.g. chart.toPie() so it displays OK.

@masayuki0812
Copy link
Member

Hi @sdarnell , Thank you for reporting. I'll check and fix this.

@masayuki0812
Copy link
Member

Hi @sdarnell , I think this has been fixed in the latest version 0.1.42. Could you try that version? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug resolved maybe
Projects
None yet
Development

No branches or pull requests

2 participants