Formatter not working when using API


I am calling API from postman with this JSON

            "Non-renewable electricity",
            "Renewable energy"
                  "rgb(0, 145, 179)",
                  "rgb(147, 149, 152)",
                  "rgb(239, 236, 235)",
                  "rgb(0, 114, 152)"
            		"display": true,
            		"formatter": "(val, ctx) => {return[ctx.dataIndex];}",
            		"color": "#fff",
            		"backgroundColor": "#404040"
            		"labels":[{"text":"64%","font":{"size": 40,"weight":"bold"}},{"text":"Renewable","font":{"size": 20}},{"text":"energy", "font":{"size": 20}}]

My doughnut kept showing the value not label.
When I tried to change the formatter return with any static value, it did not work.

I am not sure how can I use formatter when using HTTP post.
Can you correct if the above is not the right way of doing the same.

Hi @ankitwalia4u,

To solve this, don’t make the formatter function a string. Instead, pass the entire chart config as a string of javascript code.

See Using JS functions for more detail on this topic!

For example:

  "width": 600,
  "height": 300,
  "devicePixelRatio": 1.0,
  "chart": "{\"type: doughnut\", ...}"