Skip to content

C# Layout Grid Example #187

Description

@phani423

Hi ,

Can anyone help me with example code of performing Grid Layout of Box plot?

Thank you!

Activity

  1. kMutagene commented on Sep 17, 2021

    @kMutagene
    Collaborator

    You'll have to do it manually atm, i am currently working on an updated version of Chart.Grid that does this internally and will be easy to call from C# though.

    The necessary steps are:

    1. Create the charts for your grid with axis anchors that correspond to the grid position
    2. combine them
    3. add as many axes to the combined chart as needed (2 X / 2 Y in my example)

    Note that Boxplot is really awkward to use because it has no static type annotation for its parameters. This is something we should fix.

    using System;
    using Plotly.NET;
    using Plotly.NET.TraceObjects;
    using Plotly.NET.LayoutObjects;
    using static Plotly.NET.Chart2D;
    using Microsoft.FSharp.Core;
    
    namespace Plotly.NET.Tests.CSharp
    {
        class Program
        {
            static void Main(string[] args)
            {
                GenericChart.GenericChart c11 =
                    Chart2D.Chart.BoxPlot<string, int [], string, int, int, int ,int> (
                        x: "11",
                        y: new int[] { 1, 2, 3 }
                    )
                    .WithAxisAnchor(X: 1, Y: 1);           
                
                GenericChart.GenericChart c12 =
                    Chart2D.Chart.BoxPlot<string, int[], string, int, int, int, int>(
                        x: "12",
                        y: new int[] { 1, 2, 3 }
                    ).WithAxisAnchor(X: 1, Y: 2);
    
                GenericChart.GenericChart c21 =
                    Chart2D.Chart.BoxPlot<string, int[], string, int, int, int, int>(
                        x: "21",
                        y: new int[] { 1, 2, 3 }
                    ).WithAxisAnchor(X: 2, Y: 1);
    
                GenericChart.GenericChart c22 =
                    Chart2D.Chart.BoxPlot<string, int[], string, int, int, int, int>(
                        x: "22",
                        y: new int[] { 1, 2, 3 }
                    ).WithAxisAnchor(X: 2, Y: 2);
    
                Chart.Combine(new GenericChart.GenericChart[] { c11, c12, c21, c22 })
    
                    .WithXAxis(LinearAxis.init<string,string,string,string, string, string>(), StyleParam.SubPlotId.NewXAxis(1) )
                    .WithXAxis(LinearAxis.init<string,string,string,string, string, string>(), StyleParam.SubPlotId.NewXAxis(2) )
                    
                    .WithYAxis(LinearAxis.init<string,string,string,string, string, string>(), StyleParam.SubPlotId.NewYAxis(1) )
                    .WithYAxis(LinearAxis.init<string,string,string,string, string, string>(), StyleParam.SubPlotId.NewYAxis(2) )
    
                    .WithLayoutGridStyle(Rows: 2, Columns: 2)
    
                    .Show();
            }
        }
    }

    image

  2. phani423 commented on Sep 20, 2021

    @phani423
    Author

    Awesome, Thank you for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions