How to call method when parsing options from json

46 views
Skip to first unread message

Patrick Klostermeier

unread,
May 13, 2015, 10:29:12 AM5/13/15
to flot-...@googlegroups.com
Hi,

I'm having trouble to call the formatter method when i parse my options via ajax call 

{
  "data": [
    {
      "label": "Series1",
      "data": 10
    },
    {
      "label": "Series2",
      "data": 20
    },
    {
      "label": "Series3",
      "data": 30
    },
    {
      "label": "Series4",
      "data": 40
    }
  ],
  "options": {
    "series":{
      "pie":{
        "show":true,
        "radius":1,
        "label":{
          "show":true,
          "radius": "2/3",
          "formatter": "labelFormatter"
        }
      }
    },
    "legend":{
      "show":false
    }
  }
}
data.json

Initialization of flot:
plotObj = $.plot(plotArea, scope.dataset, scope.options);
The scope.options is the "options" part from the json above and the scope.dataset is the "data" part of my json

var labelFormatter = function(label, series) {
   console.log('labelformatter');
   // series is the series object for the label
   return '<a href="#' + label + '">' + label + '</a>';
};
My "labelFormatter" function

So, it's all working and it's creating the flot pie chart, but it's NOT calling the labelFormatter function.

Can i somehow pase/prepare my scope.data so javascript calls my "labelFormatter" function?

Thank you


Message has been deleted

Ced

unread,
May 13, 2015, 5:16:35 PM5/13/15
to flot-...@googlegroups.com
Remove the quotes around labelFormatter

"formatter": labelFormatter
Reply all
Reply to author
Forward
0 new messages