mattosaurus / ChartJSCore

Implementation of Chart.js for use with .NET Core.
GNU General Public License v3.0
116 stars 34 forks source link

Unclear usage of GenerateLabels #53

Closed Puharesource closed 4 years ago

Puharesource commented 4 years ago

I'm attempting to change the labels in the legend, so that they show the value next to them. Using regular ChartJS, I'd have to pass a function to generateLabels in

options = {
    legend: {
        labels: {
            generateLabels: chart => {
                // Do stuff
            }
        }
    }
}

In ChartJSCore I can only parse a string to GenerateLabels within the LegendLabel class. It seems quite unclear how I'd achieve my goal. Clarification would be much appreciated, thank you.

mattosaurus commented 4 years ago

Hi, labels are part of the legend object not the options object aren't they?

options > legend > labels

https://www.chartjs.org/docs/latest/configuration/legend.html

For the generateLabels property just set the string value to whatever you function is, this is then rendered without the standard string double quotes by the decoration [JsonConverter(typeof(PlainJsonStringConverter))].

This maybe isn't obvious in the documentation so I'll update it to make it more explicit.

Puharesource commented 4 years ago

Oh yeah, I just forgot to put in the legend object, I've edited my original issue. Thank you, I'll try it out

EDIT: Worked perfectly