最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to create a custom tooltip label for a barchart in blazorise - Stack Overflow

programmeradmin6浏览0评论

I am working on making a barchart that shows running hours. The intended display would be 3 hours and 10 minutes Using the default tooltip label would mean that this would be shown as 3.1667 hours, which isn't user friendly way of displaying the data.

Since Blazorise 1.7 it is possible to do this using the ChartTooltipCallback however I can't seem to make it work.

If I look at the class itself

Callbacks = new ChartTooltipCallbacks
{
   Label = x => "Hello world"
}

should work but I get an SystemArgumentException

Unhandled exception rendering component: The expression must return a FormattableString. (Parameter 'expression')
      System.ArgumentException: The expression must return a FormattableString. (Parameter 'expression')
         at Blazorise.Utilities.ExpressionConverter.ToTemplatedStringLiteral(LambdaExpression expression)
         at Blazorise.Utilities.Converters.<ToDictionary>g__ProcessValue|1_0(Object value, Boolean emitDefaultValue, <>c__DisplayClass1_0&)
         at Blazorise.Utilities.Converters.ToDictionary(Object source, Boolean addEmptyObjects, Boolean forceCamelCase)
         at Blazorise.Utilities.Converters.<ToDictionary>g__ProcessValue|1_0(Object value, Boolean emitDefaultValue, <>c__DisplayClass1_0&)
         at Blazorise.Utilities.Converters.ToDictionary(Object source, Boolean addEmptyObjects, Boolean forceCamelCase)
         at Blazorise.Utilities.Converters.<ToDictionary>g__ProcessValue|1_0(Object value, Boolean emitDefaultValue, <>c__DisplayClass1_0&)
         at Blazorise.Utilities.Converters.ToDictionary(Object source, Boolean addEmptyObjects, Boolean forceCamelCase)
         at Blazorise.Utilities.Converters.<ToDictionary>g__ProcessValue|1_0(Object value, Boolean emitDefaultValue, <>c__DisplayClass1_0&)
         at Blazorise.Utilities.Converters.ToDictionary(Object source, Boolean addEmptyObjects, Boolean forceCamelCase)
         at Blazorise.Charts.BaseChart`4.SetOptions(TOptions options)

I've had a look at Difference between String, FormattableString, IFormattable which explains the formattable string, but even if I change it to

Callbacks = new ChartTooltipCallbacks
{
   Label = x=> $"Hello world {x.FormattedValue}"
}

the same exception gets thrown.

发布评论

评论列表(0)

  1. 暂无评论