I had the tooltip customization on previous version 18.3.X working fine.
I updated blazor chart to version 18.4.0.42 and followed the new documentation_
https://blazor.syncfusion.com/documentation/chart/how-to/tool-tip-table/The problem is that my datasource has type decimal instead of double.
Exception:
blazor.server.js:19 [2021-02-12T10:56:26.758Z] Error: System.InvalidCastException: Unable to cast object of type 'System.Decimal' to type 'System.Double'.
at Syncfusion.Blazor.Charts.Chart.Internal.ChartTooltip.TriggerTooltipRender(PointData point, Boolean isFirst, String textCollection, String headerText)
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__140_0(Object state)
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteSynchronously(TaskCompletionSource`1 completion, SendOrPostCallback d, Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.ExecuteBackground(WorkItem item)
TEST CODE (updated from
https://blazor.syncfusion.com/documentation/chart/how-to/tool-tip-table/):
---------------------------------------------------------------
@page "/test"
@using Syncfusion.Blazor.Charts
<div class="row">
<div class="col-md-8">
<SfChart Title="Profit Comparison of A and B">
<ChartPrimaryXAxis>
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
</ChartPrimaryXAxis>
<ChartPrimaryYAxis Minimum="0" Maximum="100" Interval="25" Title="Sales">
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
</ChartPrimaryYAxis>
<ChartSeriesCollection>
<ChartSeries DataSource="@dataSource" Name="Product A" XName="x" Opacity="1" YName="y1" Type="ChartSeriesType.Column">
</ChartSeries>
<ChartSeries DataSource="@dataSource" Name="Product B" XName="x" Opacity="1" YName="y2" Type="ChartSeriesType.Column">
</ChartSeries>
</ChartSeriesCollection>
<ChartArea>
<ChartAreaBorder Width="0"></ChartAreaBorder>
</ChartArea>
<ChartTooltipSettings Enable="true">
<Template>
@{
var data = context as ChartTooltipInfo;
<table>
<tr><td>Point Value: </td><td>@data.X : @data.Y</td></tr>
<tr><td><div id="chart_cloud"><img src="https://ej2.syncfusion.com/demos/src/chart/images/cloud.png" style="width: 41px; height: 41px" /></div></td></tr>
</table>
}
</Template>
</ChartTooltipSettings>
</SfChart>
</div>
</div>
@code
{
public class ChartTooltipData
{
public decimal x { get; set; } // changed from double. I need decimal
public decimal y1 { get; set; } // changed from double. I need decimal
public decimal y2 { get; set; } // changed from double. I need decimal
}
public class SelectionData
{
public decimal x { get; set; } // changed from double. I need decimal
public decimal y { get; set; } // changed from double. I need decimal
}
private Random rnd = new Random();
public List<ChartTooltipData> dataSource = new List<ChartTooltipData>();
protected override void OnInitialized()
{
for (int i = 0; i < 5; i++)
{
dataSource.Add(new ChartTooltipData { x = 1971 + i, y1 = rnd.Next(10, 100), y2 = rnd.Next(10, 100) });
}
}
}
---------------------------------------------------------------
The exception occours even with an empty template like this:
<ChartTooltipSettings Enable="true">
<Template>
@{
var data = context as ChartTooltipInfo;
<table>
<tr><td>Point Value: </td><td>test</td></tr>
</table>
}
</Template>
</ChartTooltipSettings>