mariusmuntean / ChartJs.Blazor

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

Int instead of double - radarchart #105

Closed sowsan closed 4 years ago

sowsan commented 4 years ago

Is there a way to use the data in Int format for showing the charts instead of double?

https://github.com/mariusmuntean/ChartJs.Blazor/blob/master/src/ChartJs.Blazor/ChartJS/RadarChart/RadarDataset.cs

Joelius300 commented 4 years ago

Thanks for contacting us.

Any integer can be converted to it's floating-point counterpart and there is an implicit conversion already defined so you don't have to write additional code (most of the time; for the times you do, just google how to do it).

var list = new List<double> { 1, 2, 3, 10, 100 };
list.Add(999);

will compile just like

var list = new List<int> { 1, 2, 3, 10, 100 };
list.Add(999);

The data-structure for the radar chart is an array of numbers (source) and in JavaScript any number is a 64-bit Floating Point (source). That's why we chose to represent it as a list of doubles, which are also 64-bit Floating Points (source).

If this doesn't answer your question, please reopen and explain in more detail.

devanshidiaries commented 4 years ago

I am trying to access this Data variable to show integer valued distribution on the Radar Chart Component. I convert the existing List with values ranging from (1 to 5) to List and then assign it to the RadarDataset class's double type Data variable as shown in the code snippet below. In spite of that, the distribution on the Radar chart gives fractional values on the chart display. How do I get the int values view? @sowsan : FYI

Radar chart int

_config = new RadarConfig { Options = new RadarOptions { Title = new OptionsTitle { Display = true, Text = "CRLF Scores" } } };

            foreach (var currentvalue in assessmentValues)
                _config.Data.Labels.Add(currentvalue.Behavior);

            List<double> icscore = new List<double>();
            foreach (var currentvalue in assessmentValues)
                icscore.Add(Convert.ToDouble(currentvalue.ICScore));

            _config.Data.Datasets.Add(new RadarDataset
            {
                Data = icscore,
                Label = "IC Score",

                BorderColor = ColorUtil.FromDrawingColor(System.Drawing.Color.DarkCyan)
            });
devanshidiaries commented 4 years ago

Also, the Tooltip on the radar chart no longer shows the Dataset values marked on the chart.

Joelius300 commented 4 years ago

That's interesting 🤔 However, I'm very confident that List<double> is the correct type. If you can give me a different type to better represent a 64-bit floating point JavaScript value than a 64-bit floating point C# value, please do :)
Maybe having it be int solves your problem because it will serialize 5 as 5 instead of 5.0.

That being said, I understand that you still have trouble displaying the correct values. Unfortunately, I can't reproduce the issue with your code. The values I see on the chart are whole numbers, there aren't any fractions. Maybe I don't understand what you want to see. Please open a new issue with a complete sample to reproduce (probably just your whole razor page with the entire config; make sure to replace your assessmentValues with some demo data), the result you see (screenshot) and what you expect to see instead (image or coherent description).

Also, the Tooltip on the radar chart no longer shows the Dataset values marked on the chart.

I don't understand what you mean by that. Please create a new issue with a detailed description, screenshots, etc. in the same fashion I told you for the int/double issue.