Skip to content

Create different Chart Types in C# #70

Closed

Description

@LucasNmn

Hi there,

I am able to create different point charts in C# with Plotly. As soon as I choose a different chart type like Line, the implementation fails. It makes no difference whether I only specify the two data sequences or the whole parameters that are not required.

Is this a known issue or am i missing something?

Activity

  1. kMutagene commented on Apr 12, 2021

    @kMutagene
    Collaborator

    Hi @LucasNmn, can you give me a sample code snippet so i can test if i can reproduce what you are experiencing?

  2. LucasNmn commented on Apr 12, 2021

    @LucasNmn
    Author

    Working Sample (with Point):

    double[] x = new double[] { 1,3,4,5,6,7};
    double[] y = new double[] { 5,7,6,5,4,3};
    ...
    var chart = Chart.Point(x,y,"Sample",true,StyleParam.Symbol.Circle,"Green",1,null,null,null,null,null,null,false);

    or without optional arguments:

    var chart2 = Chart.Point(x,y);

    Not Working (for Example Line) :
    var chartLine = Chart.Line(x,y, "Sample", true, StyleParam.Symbol.Square, "Green", 1, null, null, null, null, null, null, null, null, false) ;

    or
    var charLine2 = new Chart.Line(x,y);

    So the initialization fails and Visual Studio tells me that the type arguments are not explicit.

  3. kMutagene commented on Apr 12, 2021

    @kMutagene
    Collaborator

    yep, that one is on us. In many places we let the F# type inference handle the typing of arguments for us, and that does not seem to translate well into C#. The offenders in the case of Chart.Line are the Dash and Width Parameters. When annotating those you can use Chart.Line like this:

    static void Main(string[] args)
            {
                double[] x = new double[] { 1, 2 };
                double[] y = new double[] { 5, 10 };
                GenericChart.GenericChart chart = Chart.Line<double,double,StyleParam.DrawingStyle,double>(x: x, y: y, Dash: StyleParam.DrawingStyle.Dash, Width:.2 );
                chart
                    .WithTraceName("Hello from C#", true)
                    .WithX_AxisStyle(title: "xAxis", Showgrid: false, Showline: true)
                    .WithY_AxisStyle(title: "yAxis", Showgrid: false, Showline: true)
                    .Show();
            }

    This is not ideal and i will try to fix this asap by adding explicit type annotations for all Chart Extensions.

  4. dsp6414 commented on Apr 12, 2021

    @dsp6414

    i also expect Some Csharp examples.

  5. LucasNmn commented on Apr 13, 2021

    @LucasNmn
    Author

    yep, that one is on us. In many places we let the F# type inference handle the typing of arguments for us, and that does not seem to translate well into C#. The offenders in the case of Chart.Line are the Dash and Width Parameters. When annotating those you can use Chart.Line like this:

    static void Main(string[] args)
            {
                double[] x = new double[] { 1, 2 };
                double[] y = new double[] { 5, 10 };
                GenericChart.GenericChart chart = Chart.Line<double,double,StyleParam.DrawingStyle,double>(x: x, y: y, Dash: StyleParam.DrawingStyle.Dash, Width:.2 );
                chart
                    .WithTraceName("Hello from C#", true)
                    .WithX_AxisStyle(title: "xAxis", Showgrid: false, Showline: true)
                    .WithY_AxisStyle(title: "yAxis", Showgrid: false, Showline: true)
                    .Show();
            }

    This is not ideal and i will try to fix this asap by adding explicit type annotations for all Chart Extensions.

    Ok, thanks for the tip. I will try that.

  6. LucasNmn commented on Apr 13, 2021

    @LucasNmn
    Author

    It's working. Thanks!

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