Hi,
This is a bit weird, and it might even be a framework problem. I have a date series line chart which has a date category axis and a numeric value axis. It's all working fine. I wanted to add a tooltip template so that when the user hovers over a point it shows the date and the value. I can display the value fine, but the date is always set to DateTime.MinValue for some odd reason.
My class is called UiVami and looking at my code, I can see the list of values is being created OK. Nowhere else do I ever change the Date value. In an attempt to debug it, I changed my class to have immutable properties with a constructor that throws an exception when the DateTime passed in is equal to DateTime.MinValue. This exception is being hit when I hover the mouse over a point - suggesting that something in the grid/framework is creating a new UIVami and setting the DateTime to null!
public
class
UiVami
{
public
DateTime Date {
get
; }
public
decimal
Value {
get
; }
public
UiVami(DateTime date,
decimal
value)
{
if
(date == DateTime.MinValue)
{
throw
new
Exception(
"arrgh"
);
}
Date = date;
Value = value;
}
}
I'm actually binding via this type which contains a list of of VAMIs:
public
class
UiVamiSet
{
public
string
InstrumentName {
get
;
set
; }
public
List<UiVami> Vamis {
get
;
set
; }
}
Here's my code for the chart:
<
TelerikChart
@
ref
=
"@_vamiChart"
Width
=
"100%"
Height
=
"100%"
>
<
ChartSeriesItems
>
@foreach (var vamiSet in _uiVamiSets)
{
<
ChartSeries
Type
=
"ChartSeriesType.Line"
Name
=
"@vamiSet.InstrumentName"
Field
=
"@nameof(UiVami.Value)"
CategoryField
=
"@nameof(UiVami.Date)"
Data
=
"@vamiSet.Vamis"
>
<
ChartSeriesMarkers
Visible
=
"false"
></
ChartSeriesMarkers
>
<
ChartSeriesTooltip
Visible
=
"true"
>
<
Template
>
@{ var dataItem = context.DataItem as UiVami; }
<
div
>
<
strong
>@vamiSet.InstrumentName</
strong
>
</
div
>
<
div
>
@dataItem.Date - @dataItem.Value
</
div
>
</
Template
>
</
ChartSeriesTooltip
>
</
ChartSeries
>
}
</
ChartSeriesItems
>
<
ChartValueAxes
>
<
ChartValueAxis
NarrowRange
=
"true"
>
</
ChartValueAxis
>
</
ChartValueAxes
>
<
ChartCategoryAxes
>
<
ChartCategoryAxis
Type
=
"ChartCategoryAxisType.Date"
>
<
ChartCategoryAxisLabels
Step
=
"3"
>
<
ChartCategoryAxisLabelsRotation
Angle
=
"-45"
/>
</
ChartCategoryAxisLabels
>
</
ChartCategoryAxis
>
</
ChartCategoryAxes
>
<
ChartTitle
Text
=
"Fund Performance"
></
ChartTitle
>
<
ChartLegend
Position
=
"ChartLegendPosition.Bottom"
>
</
ChartLegend
>
</
TelerikChart
>
Any help appreciated!
Thanks.