Skip to content
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

Candlestick example in C# #297

Closed
dharmatech opened this issue Jun 12, 2022 · 2 comments
Closed

Candlestick example in C# #297

dharmatech opened this issue Jun 12, 2022 · 2 comments
Labels
Area: CSharp Area: MissingAbstraction Plotly.js functionality that has to be implemented

Comments

@dharmatech
Copy link

dharmatech commented Jun 12, 2022

I have a simple program that uses Plotly.NET to create a candlestick chart of S&P 500 data:

https://github.com/dharmatech/PlotlyNetCandlestickCsv/blob/master/PlotlyNetCandlestickCsv/Program.cs

The output in a browser window is as follows:

image

Questions

Tuple.Create vs C# tuples

Note that here I had to use Tuple.Create instead of a native C# tuple:

var seq = items.Select(elt =>
    Tuple.Create(
        elt.DateTime,
        StockData.Create((double)elt.Open, (double)elt.High, (double)elt.Low, (double)elt.Close)
    ));

Will we be able to use C# tuples after #296 is implemented?

WithYAxis

Note that the call to WithYAxis is currently quite verbose:

.WithYAxis(LinearAxis.init<IConvertible, IConvertible, IConvertible, IConvertible, IConvertible, IConvertible>(
    FixedRange: false))

Are there plans to make this more concise as part of #296?

Responsive layout vs hardcoded

I currently have the chart size hardcoded via:

.WithSize(1800, 900)

It would be nice to have the chart resize based on the size of the browser window. I added the following:

.WithConfig(Config.init(Responsive: true))

but it doesn't seem to have the intended effect.

Zoom with mouse wheel

Is there a way to enable zoom via the mouse wheel?

Comments

Any suggestions regarding making the example a more idiomatic demonstration of Plotly.NET are welcome. 🙂

Thank you for Plotly.NET.

@kMutagene
Copy link
Collaborator

kMutagene commented Jun 14, 2022

Thanks for your questions/feedback, i did not know that there are differences between tuples for both languages.

Will we be able to use C# tuples after #296 is implemented?

No, we will focus on the overloads that take the dimensions of the data as separate arguments (so in the case of candlestick, that would be the one taking ohlc and time data as separate collections each). The reason for this is simply the large overhead of writing 2+ bindings for each chart type instead of initially just 1. This way, all chart types get at least 1 native C# binding faster. The overloads with tupled arguments will be next.

Note that the call to WithYAxis is currently quite verbose

Not much to be done about this, that's just how C# works with generics. The native C# binding will however provide names for the type arguments, so the correct types it will be easier to infer from intellisense (see #285 for more details).

Is there a way to enable zoom via the mouse wheel?

Scrolling via zoom is a plotly property settable on the Config object, which is currently not directly supported via Config.init - there are some other missing attributes, 'ill open a separate issue for that. You can however set it manually (this is true for everything that has no direct binding equivalent):

using Plotly.NET;

var config = new Config();
config.SetValue("scrollZoom",true);

Chart2D.Chart.Point<int,int,string>(
    x: new int [] {1,2},
    y: new int [] {1,2}
).WithConfig(config);

Any suggestions regarding making the example a more idiomatic demonstration of Plotly.NET are welcome.

I would redirect this right back at you 😉 - I don't know how idiomatic usage of Plotly.NET in C# should look like from the C# user perspective. One thing i take away from this issue is the usage of C# tuples for the overloads that take tupled data. Plotly.NET is written in F# with a C# compatibility layer, which comes with some awkwardness for C#. Some of this is solved (see #285), but any kind of feedback is greatly appreciated here. There will be a preview package of the current C# API soon.

@kMutagene kMutagene added Area: MissingAbstraction Plotly.js functionality that has to be implemented Area: CSharp labels Jul 11, 2022
@kMutagene
Copy link
Collaborator

Closing this, as there is now a C# binding available for Chart.Candlestick (and all other finance charts).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: CSharp Area: MissingAbstraction Plotly.js functionality that has to be implemented
Projects
None yet
Development

No branches or pull requests

2 participants