1

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?

1 Answer 1

0

Try adding TickFormat on your axis instead of adding tick values.

    layout = new Layout
    {
        XAxis = new List<XAxis>
        {
            new ()
            {               
                TickFormat = "%d/%m/%Y",
            }
        }
    }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.