I've been trying to use strings as axis tick labels with (Blazor) Plotly chart in C#, but doesn't seem to work. It works fine with simple numerical labels. Current source code looks as follows:
PlotlyChart chart;
Config config = new Config();
Layout layout = new Layout();
IList<ITrace> data = new[]
{
new Scatter
{
Name = "ScatterTrace",
Mode = ModeFlag.Lines,
X = new List<object>{"1", "2", "3"},
Y = new List<object>{1,2,3}
}
};
Then adding some more data to the chart through a button press:
if (!(chart.Data.FirstOrDefault() is Scatter scatter)) return;
var y = ts.GetColumn(0).ToArray().Cast<object>().ToList();
var x = Enumerable.Range(0, y.Count).Cast<object>().ToList();
var tickText = ts.Time.Select(x => x.ToString("dd/MM/yyyy")).Cast<object>().ToList();
var xAxis = new XAxis
{
TickVals = x,
TickText = tickText,
Type = Plotly.Blazor.LayoutLib.XAxisLib.TypeEnum.Category
};
layout.XAxis = new List<XAxis>();
layout.XAxis.Add(xAxis);
await chart.ExtendTrace(x, y, data.IndexOf(scatter));
The chart data shows up but still only with simple numerical x axis values. What is wrong?