You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm able to see an example chart in my Blazor Server (dotnet v.7) but I get an exception in the browser after the chart is displayed: "Microsoft.JSInterop.JSException: gd.data must be an array".
using Plotly.Blazor;
using Plotly.Blazor.Traces;
using Plotly.Blazor.Traces.ScatterLib;
using Plotly.Blazor.LayoutLib;
namespace Portal.Pages;
public partial class Charts
{
private PlotlyChart chart;
private Config config = new() { Responsive = true };
private Layout layout = new()
{
Title = new Title { Text = "Scatter" },
YAxis = new List<YAxis>
{
new()
{
Title = new Plotly.Blazor.LayoutLib.YAxisLib.Title { Text = "Scatter Unit" }
}
}
};
// Using the interface IList is important for the event callback.
IList<ITrace> data = new List<ITrace>
{
new Scatter
{
Name = "ScatterTrace",
Mode = ModeFlag.Lines | ModeFlag.Markers,
X = new List<object>{1,2,3},
Y = new List<object>{1,2,3}
}
};
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await AddData();
}
}
private async Task AddData(int count = 100)
{
if (!(chart.Data.FirstOrDefault() is Scatter scatter)) return;
var max = (int?)scatter.X?.Max();
var (x, y) = ChartsHelper.GenerateData(max + 1 ?? 0, max + 1 + count ?? count);
if (!scatter.X.Any() || !scatter.Y.Any())
{
scatter.X.AddRange(x);
scatter.Y.AddRange(y);
await chart.React();
}
else
{
await chart.ExtendTrace(x, y, data.IndexOf(scatter));
}
}
}
I'm guessing that there's either a way to swallow this exception or that I've missed something basic with setting up the example.
Any pointers gratefully received.
Note: 'ChartsHelper.GenerateData()' is a copy from the Examples code.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm able to see an example chart in my Blazor Server (dotnet v.7) but I get an exception in the browser after the chart is displayed: "Microsoft.JSInterop.JSException: gd.data must be an array".
Charts.cshtml
Charts.cshtml.cs
I'm guessing that there's either a way to swallow this exception or that I've missed something basic with setting up the example.
Any pointers gratefully received.
Note: 'ChartsHelper.GenerateData()' is a copy from the Examples code.
Beta Was this translation helpful? Give feedback.
All reactions