8

I'm trying to do a bit of charting and came across this weird error message. Here is an example of what works:

$.ajax({
    type: "GET",
    dataType: "json",
    url: "/data/active_projects_per_phase",
    success: function (result) {
        $.plot($("#active_per_phase"), result, {
            series: {
                pie: {
                    show: true,
                    label: {
                        show: true,
                        radius: 3 / 4,
                        formatter: function (label, series) {
                            return label + ': ' + series.data[0][1] + ' (' + Math.round(series.percent) + '%)';
                        },
                        background: {
                            opacity: 0.5
                        }
                    }

                }

            },
            legend: {
                show: false

            }
        });

    }
});

The url returns the following data:

[
  {
    "data": 24,
    "label": "\u0411\u0438\u0437\u043d\u0435\u0441-\u0438\u0434\u0435\u044f"
  },
  {
    "data": 31,
    "label": "\u041f\u043b\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435"
  },
  {
    "data": 26,
    "label": "\u0418\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435"
  },
  {
    "data": 1,
    "label": "\u0417\u0430\u043a\u0440\u044b\u0442\u0438\u0435"
  }
]

Yet it will not work with this data and display "Could not draw pie with labels contained inside canvas" error:

[
  {
    "data": 6,
    "label": "\u0417\u0430\u043a\u0440\u044b\u0442"
  },
  {
    "data": 11,
    "label": "\u041e\u0442\u043c\u0435\u043d\u0435\u043d"
  },
  {
    "data": 1,
    "label": "\u041e\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d"
  },
  {
    "data": 5,
    "label": "\u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d \u0432 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442"
  },
  {
    "data": 4,
    "label": "\u041f\u0435\u0440\u0435\u043d\u0435\u0441\u0435\u043d \u0432 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443"
  }
]

What is it that I'm missing in chart setup to overcome this?

2 Answers 2

12

The pie functionality of flot has restrictions on the legend and labels. The code makes sure that the legend/labels stays within the boundaries of the canvas, and if it doesn't it fails as you have seen. Your options are:

  1. Make your canvas bigger
  2. Make your labels shorter
  3. Use a legend outside of the canvas using the legend.container option to specify an outside div
1
  • 3. Option not apply because the message is for $p.series.pie.label, not legends in plot. ($p is placeholder).
    – Sith2021
    Dec 11, 2016 at 21:59
1

try reducing the text of the label, or try reducing the radius of label, i took a cue from here http://people.iola.dk/olau/flot/examples/pie.html

i reduced the radius of my label and the issue was fixed for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.