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

Customising ChartTypes class #25

Closed
oleksiizapara opened this issue May 31, 2019 · 2 comments
Closed

Customising ChartTypes class #25

oleksiizapara opened this issue May 31, 2019 · 2 comments

Comments

@oleksiizapara
Copy link

I found a great extension for chartJS which allows to create candlestick chart. https://github.com/chartjs/chartjs-chart-financial

I tired to implement Blazor extension version based on ChartJs.Blazor, However, I found that I cannot add additional ChartTypes. I used reflection to create valid objects.

public static class ChartTypeFactory
 {
     public static ChartTypes CreateCandlestick() =>
      Construct<ChartTypes>(
          new Type[] { typeof(string) },
          new object[] { "candlestick" }
      );

     public static ChartTypes CreateOhlc() =>
     Construct<ChartTypes>(
         new Type[] { typeof(string) },
         new object[] { "ohlc" }
     );

     public static T Construct<T>(Type[] paramTypes, object[] paramValues)
     {
         Type t = typeof(T);

         ConstructorInfo ci = t.GetConstructor(
             BindingFlags.Instance | BindingFlags.NonPublic,
             null, paramTypes, null);

         return (T)ci.Invoke(paramValues);
     }
 }

The sample project with candlestick chart can be access via link https://github.com/oleksiizapara/ChartJsBlazorFinancialSample

I hope that in future release the library will be able to do it straightforward.

May be it can be done via base class that can be inherited?

@SeppPenner
Copy link
Contributor

If I was you, I would take a look at https://github.com/Joelius300/ChartJSBlazor. This project is maintained at least.

@Joelius300
Copy link
Contributor

We should add a ChartType.Custom(string chartType) method to the ChartType-'enum' with a summary along the lines of

This method constructs a <see cref="ChartType" /> which represents the given value. Only use this method if you're implementing your own chart e.g. for a chart.js extension, otherwise use the given values.

I'm adding this to the backlog so it can be added in a feature release.

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

3 participants