Skip to content

[C#] 3D Volume example in C# #344

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
ShannonZ opened this issue Aug 22, 2022 · 2 comments
Closed

[C#] 3D Volume example in C# #344

ShannonZ opened this issue Aug 22, 2022 · 2 comments

Comments

@ShannonZ
Copy link

ShannonZ commented Aug 22, 2022

Description

I've googled servaral days but I cannot find any materials about how to use Plotly.Net in C# language.
The most relevant content I've found is:
https://plotly.net/03_5_3d-volume-plots.html

I've tried to translate the code line by line from F# to C#. But the core part Chart.Volume() seems to have a different signature.
Chart3D.Chart.Volume<**a, b, c, d, e, f, g**>(System.Collections.Generic.IEnumerable<a>, System.Collections.Generic.IEnumerable<b>, System.Collections.Generic.IEnumerable<c>, System.Collections.Generic.IEnumerable<d>, Microsoft.FSharp.Core.FSharpOption<string>, Microsoft.FSharp.Core.FSharpOption<bool>, Microsoft.FSharp.Core.FSharpOption<double>, Microsoft.FSharp.Core.FSharpOption<e>, Microsoft.FSharp.Core.FSharpOption<System.Collections.Generic.IEnumerable<e>>, Microsoft.FSharp.Core.FSharpOption<Plotly.NET.StyleParam.Colorscale>, Microsoft.FSharp.Core.FSharpOption<bool>, Microsoft.FSharp.Core.FSharpOption<Plotly.NET.ColorBar>, Microsoft.FSharp.Core.FSharpOption<double>, Microsoft.FSharp.Core.FSharpOption<double>, Microsoft.FSharp.Core.FSharpOption<Plotly.NET.TraceObjects.Caps>, Microsoft.FSharp.Core.FSharpOption<Plotly.NET.TraceObjects.Slices>, Microsoft.FSharp.Core.FSharpOption<Plotly.NET.TraceObjects.Surface>, Microsoft.FSharp.Core.FSharpOption<System.Collections.Generic.IEnumerable<f>>, Microsoft.FSharp.Core.FSharpOption<bool>)

I don't know how to set the a,b,c,d,e,f,g. Consequently, I cannot call this function.

Expected behavior

I want a runnable C# version of the official volume rendering demo.
Any tutorials about how to use plotly WITH C# would be appreaciated.

Known workarounds

Please provide a description of any known workarounds.

Related information

  • Operating system: Win10
  • Branch:Latest Stable from nuget
  • .NET Runtime: framework4.7.2
@kMutagene
Copy link
Collaborator

kMutagene commented Aug 22, 2022

But the core part Chart.Volume() seems to have a different signature

That's not completely correct, C# just forces you to make these annotations for the generics, while F# can infer them (see #285).

In general for usage from C#, I'd suggest using our new, more idiomatic Plotly.NET.CSharp API. You won't get around making these annotations, although that API minimizes the amount of generics used. Also, it provides names for the generics so you're more informed when setting them:

image

I want a runnable C# version of the official volume rendering demo.

That would require rewriting the helper functions used in that tutorial in C#. For the time being, here's a simple example:

Chart.Volume<double,double,double,double,string,double>(
    x: new double [] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 2, 2, 2, 2, 2, 2, 2, 2, 2 },
    y: new double [] { 1, 1, 1, 1.5, 1.5, 1.5, 2, 2, 2, 1, 1, 1, 1.5, 1.5, 1.5, 2, 2, 2, 1, 1, 1, 1.5, 1.5, 1.5, 2, 2, 2 },
    z: new double [] { 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2, 1, 1.5, 2},
    value: new double [] { 0.8414709848, 0.6649966577, 0.4546487134, 0.6649966577, 0.3458103097,04704000269, 0.4546487134, 04704000269, -0.1892006238, 0.6649966577, 0.3458103097, 04704000269, 0.3458103097, -06853149997, -0.217228915,04704000269, -0.217228915, -0465692497, 0.4546487134, 04704000269,-0.1892006238, 04704000269, -0.217228915, -0465692497, -0.1892006238,-0465692497, 0.1236697808},
    Name: "volume",
    ShowLegend: true
)

If you rewrite the helper code, it would be greatly appreciated if you would add it here, since it is planned to provide C# docs once the C# chart bindings are completed (#296)

image

@kMutagene
Copy link
Collaborator

Closing this until further feedback

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

No branches or pull requests

2 participants