I specifically ran into this issue with the Legend model and the OnClickproperty. I kept getting an error that "onClick" was not a function, and indeed it was not. It was being rendered as a string: "onClick": "function (e) { e.stopPropagation(); }"...
I took a look at how other callbacks are implemented and it appears that the callback properties should be decorated with [JsonConverter(typeof(PlainJsonStringConverter))] in order for them to be serialized correctly. Every callback in the Legend model is probably broken (I took a look at another model and indeed this attribute is missing there too).
A hotfix for my project was to simply extend the class and hide the damaged property:
using ChartJSCore.Helpers;
using ChartJSCore.Models;
using Newtonsoft.Json;
namespace MyNamespace
{
public class MyLegend : Legend
{
[JsonConverter(typeof(PlainJsonStringConverter))]
public new string OnClick { get; set; }
}
}
and applying that to my option in implementation
return new Chart
{
Options = new Options
{
Legend = new MyLegend
{
OnClick = "function (e) { e.stopPropagation(); }"
}
}
}
I specifically ran into this issue with the
Legend
model and theOnClick
property. I kept getting an error that "onClick" was not a function, and indeed it was not. It was being rendered as a string:"onClick": "function (e) { e.stopPropagation(); }"
...I took a look at how other callbacks are implemented and it appears that the callback properties should be decorated with
[JsonConverter(typeof(PlainJsonStringConverter))]
in order for them to be serialized correctly. Every callback in the Legend model is probably broken (I took a look at another model and indeed this attribute is missing there too).A hotfix for my project was to simply extend the class and hide the damaged property:
and applying that to my option in implementation