const options = {
scales: {
y: {
ticks: {
callback: function(value, index, ticks) { return value + '%'; }
},
// ...
}
}
};This will make each tick's value followed by |
Replies: 1 comment
|
You did not miss it: A small JS interop helper is a workable solution for now. Give the chart a stable ID: @inject IJSRuntime JS
<LineChart Id="percent-chart" @ref="lineChart" />Add this to a JS file loaded after Chart.js/BlazorBootstrap: window.setPercentYAxisTicks = (canvasId) => {
const chart = Chart.getChart(canvasId);
const ticks = chart?.options?.scales?.y?.ticks;
if (!ticks) return;
ticks.callback = (value) => `${value}%`;
chart.update("none");
};Then apply it immediately after initialization: await lineChart.InitializeAsync(chartData, lineChartOptions);
await JS.InvokeVoidAsync("setPercentYAxisTicks", "percent-chart");
One important detail: call the helper again after every BlazorBootstrap So the short answer is: not implemented as a first-class C# option yet; JS interop is required unless the library adds a dedicated formatter/callback bridge. |
You did not miss it:
ticks.callbackis not exposed by the current BlazorBootstrap chart API. The currentChartAxesTicksmodel contains the serializable styling options, but noCallbackproperty. A JavaScript function also cannot be transferred as a normal .NET delegate through JSON interop.A small JS interop helper is a workable solution for now. Give the chart a stable ID:
Add this to a JS file loaded after Chart.js/BlazorBootstrap: