Create a separete Database Table for each Chart?

osyris 236 Reputation points
2022-04-04T12:20:05.113+00:00

I have About 6 Charts on my website

I have a code script that first gets all the dates in a year and adds it to a model List
that model list contains 2 values: "Date" and "Value" (for the chart X and Y axis),
the dates are all set with the "DateTime" function and the "Value" is set to "0";
so this list contains around 360 items with the dates of an entire year and the value on 0

Then It checks all Products that have been sold on each Date in the "Model list"
if it does it will overrite the "Value" if it doesnt it leaves it "0"
then It strips off the hours so it appears shorter and cleaner in the X Axis in the chart.

this entire process could delay the loading on a admin page
So my question is should i create a Database table with 360 Collums? or would that be crazy?
or would it not slow down the loading speed
I dont know if the first method i already used is the normal way of getting Data for a chart or if there are better way

Please let me know,

Thanks :-)

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,292 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,374 questions
{count} votes

1 answer

Sort by: Most helpful
  1. osyris 236 Reputation points
    2022-04-04T16:21:04.58+00:00

    why would you need 360 columns?

    Im sorry I ment 360 rows with 2 columms

    The forum members cannot see your code

    Here is my code:
    In this example I used Data from 1 month

     public List<ChartData> MonthDates()
            {
                int month = DateTime.Now.Month;
                int year = DateTime.Now.Year;
                int Days = DateTime.DaysInMonth(year, month);
    
                var DateList = new List<ChartData>();
                var GetDate = new DateTime(year, month, 1);
    
                for (int i = 0; i != Days; i++)
                {
                    var chart = new ChartData();
                    chart.name = GetDate.ToShortDateString();
                    chart.value = 0;
    
                    DateList.Add(chart);
    
                    GetDate = GetDate.AddDays(1);
                }
                return DateList;
            }
    
            [HttpGet("SoldItems")]
            public async Task<IActionResult> SoldItems()
            {
                var items = await _dbContext.placedOrderGroups.ToListAsync();
    
                   var SoldChart = new List<ChartData>(MonthDates());
    
                var test = new DateTime(2019, 6, 11);
                string day = test.Day.ToString();
    
    
                    foreach (var item in SoldChart)
                    {
                    var getValue = items.Where(x => x.Time.ToShortDateString() == item.name).ToList();
    
    
                    var X = SoldChart.FirstOrDefault(x => x == item);
                    string RemoveYear = X.name.Substring(0, X.name.Length - 5);
                    string newDate = RemoveYear.Replace("-", " / ");
                    X.name = newDate;
    
    
                    int NewValue = 0;
                    if (getValue.Count > 0)
    
                        foreach(var x in getValue)
                            NewValue = NewValue + x.TotalProduct;
    
                        SoldChart.FirstOrDefault(x => x == item).value = NewValue;
                    }
    
                return Ok(SoldChart);
            }
    
    0 comments No comments