Code Monkey home page Code Monkey logo

Comments (6)

sean-mcl avatar sean-mcl commented on May 20, 2024

Hi Jannes,

I'm on vacation right now and should have time again in a week. I will then upload an example.
If you have already found a solution in that time, you can create a pull-request if you want to.

Greetings

Sean

from plotly.blazor.

EuanKirkhope avatar EuanKirkhope commented on May 20, 2024

Working surface map:

@using Plotly.Blazor
@using PBT = Plotly.Blazor.Traces
@using PBL = Plotly.Blazor.LayoutLib

@inject yourdatabase db;

<PlotlyChart style="height: 60vh; min-height: 150px" @bind-Config="config" @bind-Layout="layout" @bind-Data="data" @ref="chart" />

@code
{

    Plotly.Blazor.PlotlyChart chart;

    Plotly.Blazor.Config config = new Plotly.Blazor.Config
    {
        Responsive = true//,
                         //DisplayModeBar = Plotly.Blazor.ConfigLib.DisplayModeBarEnum.False
    };

    Plotly.Blazor.Layout layout = new Plotly.Blazor.Layout
    {
        Title = new PBL.Title
        {
            Text = "Surface",
            Font = new PBL.TitleLib.Font
            {
                Color = "#AAA"
            }
        },
        Legend = new PBL.Legend
        {
            Font = new PBL.LegendLib.Font
            {
                Color = "#AAA"
            }
        },
        XAxis = new List<PBL.XAxis>
       {
            new PBL.XAxis
            {
                Title = new PBL.XAxisLib.Title
                {
                    Text = "Position (m)",
                    Font = new PBL.XAxisLib.TitleLib.Font
                    {
                        Color = "#AAA"
                    }
                }
            }
        },
        YAxis = new List<PBL.YAxis>
       {
            new PBL.YAxis
            {
                Title = new PBL.YAxisLib.Title
                {
                    Text = "Time",
                    Font = new PBL.YAxisLib.TitleLib.Font
                    {
                        Color = "#AAA"
                    }
                }
            }
        },

        Scene = new List<PBL.Scene>
        {
            new PBL.Scene{
                XAxis = new PBL.SceneLib.XAxis
                {
                    Title = new PBL.SceneLib.XAxisLib.Title
                    {
                        Text = "Position (m)",
                        Font = new PBL.SceneLib.XAxisLib.TitleLib.Font
                        {
                            Color = "#AAA"
                        }
                    }
                },
                YAxis = new PBL.SceneLib.YAxis
                {
                    Title = new PBL.SceneLib.YAxisLib.Title
                    {
                        Text = "Time",
                        Font = new PBL.SceneLib.YAxisLib.TitleLib.Font
                        {
                            Color = "#AAA"
                        }
                    }
                },
                ZAxis = new PBL.SceneLib.ZAxis
                {
                    Title = new PBL.SceneLib.ZAxisLib.Title
                    {
                        Text = "Angle (ΒΊ)",
                        Font = new PBL.SceneLib.ZAxisLib.TitleLib.Font
                        {
                            Color = "#AAA"
                        }
                    }
                },
                Camera = new PBL.SceneLib.Camera
                {
                    Eye = new PBL.SceneLib.CameraLib.Eye
                    {
                        X = 2.5m,Y = 2m, Z = 0.5m
                    },
                    Up = new PBL.SceneLib.CameraLib.Up
                    {
                        X = 0m, Y = 0m, Z = 1m
                    },
                    Center = new PBL.SceneLib.CameraLib.Center
                    {
                        X = 0m, Y = 0m, Z = -0.3m
                    }
                },
                AspectMode = PBL.SceneLib.AspectModeEnum.Manual,
                AspectRatio = new PBL.SceneLib.AspectRatio
                {
                    X = 2m, Y = 3m, Z = 1m
                }
            }
        },

        PaperBgColor = "#262626",
        PlotBgColor = "#262626",
    };

    IList<ITrace> data = new List<ITrace>
    {
        new PBT.Surface
        {
            Name = "SurfaceTrace",

            X = new List<object>(),
            Y = new List<object>(),
            Z = new List<object>(),
            ColorBar = new PBT.SurfaceLib.ColorBar()
            {
                OutlineColor = "#AAA",
                BorderColor = "#AAA",
                TickColor = "#AAA",
                TickFont = new PBT.SurfaceLib.ColorBarLib.TickFont
                {
                    Color = "#AAA"
                }
            }
        }
    };

    List<object> xVals;

    private async Task SetData()
    {
        var angles = await db.GetAngles();
        var h = data[0] as PBT.Surface;
        int maxIdx = 0;

        if (angles == null || angles.Count() < 1)
            return;

        List<object> z = new List<object>();

        foreach (var item in angles)
        {
            h.Y.Add(item.Id); // row in database or datetime for time axis
            maxIdx = Math.Max(maxIdx, item.Pitch.Length); // this should not change or explosion
            z.Add(item.Roll);  // Roll is a float[] of same length as x axis item array
        }

        h.Z = z;

        if (xVals == null)
        {
            xVals = new List<object>(maxIdx);
            for (int i = 0; i < maxIdx; i++)
            {
                xVals.Add(i);
            }
        }

        h.X = xVals;
    }

    protected override async Task OnAfterRenderAsync(bool firstRender)
    {
        if (firstRender)
        {
            try
            {
                await SetData();
                await chart.NewPlot();
            }
            catch (Exception e)
            {

            }
        }
    }
}

from plotly.blazor.

EuanKirkhope avatar EuanKirkhope commented on May 20, 2024

TLDR: setting the Y axis (or any X too presumably) to a Datetime doesn't work.

I've found that in the example above if I set the line:

h.Y.Add(item.Id); // row in database or datetime for time axis

from the db row id (integer) to timestamp (DateTime), the surface graph no longer appears, and a heatmap shows the first row repeated.

from plotly.blazor.

JannesRed avatar JannesRed commented on May 20, 2024

Hi, thanks! Obviously new to this package. I've managed to get a working surface map with some minor modifications to the heatmap code.

There seems to be an XCalendar property on the Surface class which I assume has to be set to Gregorian for datetime arrays to work. Will definitely fiddle around here.

And yes, the Z axis needs to be some arrays in an array to match the data in the X and Y axes.

from plotly.blazor.

sean-mcl avatar sean-mcl commented on May 20, 2024

Added a surface example in v1.2.0.

Have a great week :)

from plotly.blazor.

JannesRed avatar JannesRed commented on May 20, 2024

Thank you, Sean :)

from plotly.blazor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.