Answered by:
ChartJSCore. Charts in ASP.Net Core

Question
-
User1554758465 posted
Hi ,
I'm trying to use charts in my ASP.Net core web application. I found this interesting https://github.com/mattosaurus/ChartJSCore.
After downloading the Nuget Package. I added the Chartcontroller and the Chart view folder with its index. and (Data, Dataset, Base) in my Model folder. Also, The plugins folder which contain (PluginDynamic) file.
everything seems ok except that the following lines in the actions of controller
- Data data = new Data(); //This line give me the following error : CS0118 error 'Data' is a namespace but is used like a type.
- Data = new List<double>() { 11, 16, 7, 3, 14 } //This line give me the following error : CS0266 cannot implicitly convert type 'system.collections.generic.list<double>' to 'system.collections.generic.IList<double?>'. An explicit conversion exist.
Any help or guides is much appreciated.
Thank you in advance.
Wednesday, August 26, 2020 5:03 PM
Answers
-
User711641945 posted
Hi ShahadAlshuhail
Data data = new Data(); //This line give me the following error : CS0118 error 'Data' is a namespace but is used like a type.Try to specify the namespace like below:
ChartJSCore.Models.Data data = new ChartJSCore.Models.Data();
Data = new List<double>() { 11, 16, 7, 3, 14 } //This line give me the following error : CS0266 cannot implicitly convert type 'system.collections.generic.list<double>' to 'system.collections.generic.IList<double?>'. An explicit conversion exist.You could see the source code below:
namespace ChartJSCore.Models { public class Dataset : Base { public Dataset(); public IList<double?> Data { get; set; } public string Label { get; set; } public bool? Hidden { get; set; } } }
So you need to change your code like below:
Data = new List<double?>() { 11, 16, 7, 3, 14 }
Best Regards,
Rena
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 27, 2020 6:19 AM
All replies
-
User-474980206 posted
you are missing the using statements
using ChartJSCore.Helpers; using ChartJSCore.Models;
As the point of this library is to serialize datasets for chart.js, you should be using the typed dataset for the chart type you want. See tests
https://github.com/mattosaurus/ChartJSCore/tree/master/src/ChartJSCoreTest
Wednesday, August 26, 2020 7:42 PM -
User711641945 posted
Hi ShahadAlshuhail
Data data = new Data(); //This line give me the following error : CS0118 error 'Data' is a namespace but is used like a type.Try to specify the namespace like below:
ChartJSCore.Models.Data data = new ChartJSCore.Models.Data();
Data = new List<double>() { 11, 16, 7, 3, 14 } //This line give me the following error : CS0266 cannot implicitly convert type 'system.collections.generic.list<double>' to 'system.collections.generic.IList<double?>'. An explicit conversion exist.You could see the source code below:
namespace ChartJSCore.Models { public class Dataset : Base { public Dataset(); public IList<double?> Data { get; set; } public string Label { get; set; } public bool? Hidden { get; set; } } }
So you need to change your code like below:
Data = new List<double?>() { 11, 16, 7, 3, 14 }
Best Regards,
Rena
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 27, 2020 6:19 AM