Stock data points do not appear
I am building a web app using .net 8 Blazor using Visual Studio. I have copied the Syncfusion candle chart demo into the project with a few modifications. (The stock data comes from Yahoo finance.) The code is shown below.
When I navigate to the page, the chart axes and title are shown, but the data points are not shown. However, if I make any changes to the page in VS and then do a hot reload, the data points do appear! That is, they are shown until I navigate to another page and return. Then again, only the axes and title have been rendered.
Somehow, the hot reload causes the data points to appear. You will see from the code below, I am using the Interactive Server render mode.
Is this some incompatibility of Syncfusion with .net 8? Or VS?
@page "/chart/hilo-open-close"
@using Syncfusion.Blazor
@using Syncfusion.Blazor.Charts
@using System.Net.Http.Json
@using Syncfusion.Blazor.Charts.Chart.Internal
@inject NavigationManager NavigationManager
@inject HttpClient Http
@rendermode InteractiveServer
<h3>HILO Chart</h3>
<div class="control-section" align='center'>
<SfChart Title="AAPL Historical" Width="@Width">
<ChartArea>
<ChartAreaBorder Width="0"></ChartAreaBorder>
</ChartArea>
<ChartPrimaryXAxis ValueType="Syncfusion.Blazor.Charts.ValueType.DateTime">
<ChartAxisCrosshairTooltip Enable="true"></ChartAxisCrosshairTooltip>
<ChartAxisMajorGridLines Width="0"></ChartAxisMajorGridLines>
</ChartPrimaryXAxis>
<ChartPrimaryYAxis Title="Price" RangePadding="ChartRangePadding.None" Interval="20" LabelFormat="n0">
<ChartAxisLineStyle Width="0"></ChartAxisLineStyle>
<ChartAxisMajorTickLines Width="0"></ChartAxisMajorTickLines>
</ChartPrimaryYAxis>
<ChartLegendSettings Visible="false"></ChartLegendSettings>
<ChartTooltipSettings Enable="true" Shared="true" Header="" Format="<b>Apple Inc.(AAPL)</b> <br> High : <b>${point.high}</b> <br> Low : <b>${point.low}</b> <br> Open : <b>${point.open}</b> <br> Close : <b>${point.close}</b> "></ChartTooltipSettings>
<ChartCrosshairSettings Enable="true" LineType="LineType.Vertical">
</ChartCrosshairSettings>
<ChartSeriesCollection>
<ChartSeries DataSource="@ChartPointsList" Name="Apple Inc.(AAPL)" XName="Period" High="High" Low="Low" Open="Open" Close="Close" Volume="Volume"
BearFillColor="#2ecd71" BullFillColor="#e74c3d" Type="ChartSeriesType.Candle">
</ChartSeries>
</ChartSeriesCollection>
</SfChart>
</div>
@code {
private Theme Theme { get; set; }
public string Width { get; set; } = "90%";
public HLOCData[] ChartPoints { get; set; } = new HLOCData[] { };
public List<HLOCData> ChartPointsList { get; set; } = new List<HLOCData>();
protected override async Task OnInitializedAsync()
{
ChartPointsList = await CreateDataListAsync();
}
protected override void OnInitialized()
{
Width="90%";
}
public class HLOCData
{
public DateTime Period { get; set; }
public double High { get; set; }
public double Low { get; set; }
public double Open { get; set; }
public double Close { get; set; }
public long Volume { get; set; }
}
public async Task<List<HLOCData>> CreateDataListAsync()
{
DateTime startDate = new DateTime(2021, 1, 1);
DateTime endDate = new DateTime(2021, 12, 31);
var data = await FetchYahooData.GetYahooDataAsync("AAPL", startDate, endDate);
List<HLOCData> hlocData = new List<HLOCData>();
foreach (var item in data)
{
HLOCData hloc = new HLOCData();
hloc.Period = item.DateTime;
hloc.High = (double)item.High;
hloc.Low = (double)item.Low;
hloc.Open = (double)item.Open;
hloc.Close = (double)item.Close;
hloc.Volume = item.Volume;
hlocData.Add(hloc);
}
return hlocData;
}
}
I found a fix to my problem! In App.razor, I replaced
<script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script>
with
<script src="https://cdn.syncfusion.com/blazor/26.1.35/syncfusion-blazor.min.js" type="text/javascript"></script>
Hi Dennis,
Greetings from Syncfusion.
We are glad to hear that replacing the script source in App.razor resolved your issue. By default, empty chart will be rendered when script is not referred or when the required script is not referred properly in sample. We have prepared sample based on your provided code snippet. Please check with the below sample and screenshot.
Sample : https://www.syncfusion.com/downloads/support/directtrac/general/ze/HiloChart-519135299.zip
For more information about script reference, please check with below code snippet and documentation link.
|
Individual NuGet(Synfusion.Blazor.Charts) |
Common NuGet(Syncfusion.Blazor) |
|
<head> <link rel='nofollow' href="_content/Syncfusion.Blazor.Themes/bootstrap5.css" rel="stylesheet" /> <script src="_content/Syncfusion.Blazor.Core/scripts/syncfusion-blazor.min.js" type="text/javascript"></script> </head> |
<head> <link rel='nofollow' href="_content/Syncfusion.Blazor/styles/bootstrap5.css" rel="stylesheet" /> <script src="_content/Syncfusion.Blazor/scripts/syncfusion-blazor.min.js" type="text/javascript"></script> </head> |
UG : https://blazor.syncfusion.com/documentation/common/adding-script-references
If you encounter any further issues or have additional questions, please don't hesitate to contact us. We're here to help!
Regards,
Durga Gopalakrishnan.
- 2 Replies
- 2 Participants
-
DI Dennis Imbro
- Jul 18, 2024 04:12 PM UTC
- Jul 19, 2024 11:10 AM UTC