mariusmuntean / ChartJs.Blazor

Brings Chart.js charts to Blazor
https://www.iheartblazor.com/
MIT License
687 stars 152 forks source link

Unable to pass data to line chart other then TimeTuple<object> #50

Closed mkopara closed 4 years ago

mkopara commented 4 years ago

Describe the bug

It is impossible to declare dataset with object such as decimal, integer etc. I only managed to successfully created a chart if TData is of Type TimeTuple for example LineDataset<TimeTuple> where TData is always a class according to this. public class LineDataset : BaseMixableDataset where TData : class

Which Blazor project type is your bug related to?

Which charts does this bug apply to?

LineChart

Joelius300 commented 4 years ago

This is not a bug. Currently it's impossible to use value types for the datasets that implement the covariant IMixableDataset (because covariance only works for reference types).
You have to use the wrappers in the ChartJs.Blazor.ChartJS.Common.Wrappers namespace. There are also extension methods for enumerables of those types (Wrap) which wraps all of the elements in the corresponding wrapper.

This limitation is known and I'd love to get rid of it in a feature version. I'm sorry but currently there is no other way than to use the wrappers.

schuttea commented 4 years ago

Hello is it possible to make something this working:

    LineDataset<DoubleWrapper> _lineset = new LineDataset<DoubleWrapper>();
    _lineset.Label = "Earnings";
    _lineset.BackgroundColor = ColorUtil.FromDrawingColor(System.Drawing.Color.Blue);
    _lineset.BorderColor = ColorUtil.FromDrawingColor(System.Drawing.Color.Blue);
    _lineset.Fill = false;
    _lineset.AddRange(new double[] { 100, 500, 150, 1000, 2000, 1500 }.Wrap());
    _lineConfig.Data.Datasets.Add(_lineset);
    _lineConfig.Data.Labels = new List<string>();
    _lineConfig.Data.Labels.AddRange(new[] { "January", "February", "March", "April", "May", "June", "July" });

The only way i can plot some data on my graph is by using Points

Joelius300 commented 4 years ago

What's the error you get? @schuttea

schuttea commented 4 years ago

No errors just no plotting of the data.

By making my example a bit more complex with the XAxes having a TimeAxis and the right Format And the plots with a TimeTuple it works perfect. But I think it could be simpeler. Thx for responding

Joelius300 commented 4 years ago

I'm sorry, I don't understand your question. Could you open a new issue with some more detail? By that I mean all the code (not just the dataset), screenshots and the expected result. Without more explanation, it's really hard for us to help you.

Thank you.