ChartDataLabelsOptions/ChartDataLabelsDataset Does not work with complex data type #5144
-
I have a bar chart that uses a complex type for it's underlying values and I want the chart data label to be a custom value as well. Ideally, something as simple as a properly formatted string but it doesn't look like that option exists. <BarChart @ref="_barChartStacked" TItem="DataPoint" Options="_barChartOptions2">
<ChartDataLabels TItem="DataPoint" Datasets="@_barDataLabelsDatasets" Options="@_barDataLabelsOptions" />
</BarChart> However, I want to be able to have a custom Label so I can have that text be whatever I want. Here is my ChartDataLabelsDataset: readonly List<ChartDataLabelsDataset> _barDataLabelsDatasets = new()
{
new()
{
DatasetIndex = 0,
Options = new()
{
BackgroundColor = "#00ff00",
BorderColor = "#00ff00",
}
},
new ()
{
DatasetIndex = 1,
Options = new ()
{
BackgroundColor = "Yellow",
BorderColor = "Blue",
// Labels = "Chicken" //I tried setting this property
}
}
}; I tried setting the Labels property on one of the datasets since the chartjs plugin seems to check if that property exists but no dice. Anyone have any thoughts on if this is possible? Or would this need to be a feature reuest? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
Playing around with the underlying chartjs plugin, I see that I can set up a custom formatter like so. So my question ultimately boils down to is this currently possible with this nuget package? Digging into it I see that the |
Beta Was this translation helpful? Give feedback.
-
readonly List<ChartDataLabelsDataset> _barDataLabelsDatasets = new()
{
new()
{
DatasetIndex = 0,
Options = new()
{
BackgroundColor = "#00ff00",
BorderColor = "#00ff00",
SoftCodeFormatter = "function(value, context) { return '£' + value.y; }"
}
},
new ()
{
DatasetIndex = 1,
Options = new ()
{
BackgroundColor = "Yellow",
BorderColor = "Blue",
SoftCodeFormatter = "function(value, context) { return '$' + value.y; }"
}
}
}; With the complex object looking like: public class DataPoint
{
public int Y { get; set; }
public string X { get; set; } = null!;
} |
Beta Was this translation helpful? Give feedback.
#5146
With the complex object looking like: