I’ve been struggling to understand how XAxis.TickText
and XAxis.DTick
work in Plotly.Blazor. I’ve been using the code in this question as a rough guide, but no matter what I do, the labels on the x-axis will not change. My current code looks like so:
@using Plotly.Blazor
@using Plotly.Blazor.Traces
@using Plotly.Blazor.LayoutLib
<PlotlyChart @bind-bind-Config="config" @bind-bind-Layout="layout" @bind-Data="data" />
@code {
string XAxisLabel = "Test Label";
List<Point> Points = new List<Point>(new Point(0, 1, "Jan"), new Point(0.5, 1.1, "Feb"), new Point(1, 0.8, "Mar"));
Config config = new Config();
Layout layout = new Layout();
IList<ITrace> data = new List<ITrace>();
protected override void OnInitialized()
{
Scatter S = new Scatter();
S.TextArray = new List<string>();
S.Mode = Plotly.Blazor.Traces.ScatterLib.ModeFlag.Lines | Plotly.Blazor.Traces.ScatterLib.ModeFlag.Markers;
S.X = new List<object>();
S.Y = new List<object>();
Dictionary<double, string> XAxisTicks = new Dictionary<double, string>();
foreach (Point P in Points)
{
S.X.Add(P.x);
S.Y.Add(P.y);
S.TextArray.Add(P.PersonalLabel);
if (!P.PersonalLabel.Equals(string.Empty)) XAxisTicks[P.x] = P.PersonalLabel;
else if (!XAxisTicks.ContainsKey(P.x)) XAxisTicks[P.x] = P.x.ToString();
}
IList<object> IListLabels = new List<object>();
foreach (string TickLabel in XAxisTicks.Values)
{
IListLabels.Add(TickLabel);
}
layout.XAxis = new List<XAxis> { new() { Title = new Plotly.Blazor.LayoutLib.XAxisLib.Title { Text = XAxisLabel },
DTick = 1,
TickMode = Plotly.Blazor.LayoutLib.XAxisLib.TickModeEnum.Array,
TickText = IListLabels } };
data.Add(S);
}
public class Point
{
public double x;
public double y;
public string PersonalLabel = string.Empty;
public Point()
{
x = 0.0;
y = 0.0;
}
public Point(double xValue, double yValue, string Label)
{
x = xValue;
y = yValue;
PersonalLabel = Label;
}
}
}
However, despite IListLabels
containing decidely non-numeric strings, the labels on the x-axis remain the same. Setting XAxis.DTick
to 1 will not even remove the ticks whose values are not integers. I know that if my code setting XAxis.TickText
worked, then setting XAxis.DTick
to 1 wouldn’t do anything, but it fails to accomplish anything even when I remove the XAxis.TickMode
and XAxis.TickText
sets from the initialization call.
Any insight into how this port of Plotly works is greatly appreciated.