Skip to content

C# Layout Grid Example #187

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phani423 opened this issue Sep 16, 2021 · 2 comments
Closed

C# Layout Grid Example #187

phani423 opened this issue Sep 16, 2021 · 2 comments

Comments

@phani423
Copy link

Hi ,

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

Thank you!

@kMutagene
Copy link
Collaborator

kMutagene commented Sep 17, 2021

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

@phani423
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants