Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8554485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:53:35+00:00 2026-06-11T14:53:35+00:00

I have spent a good few days learning linq and producing json results from

  • 0

I have spent a good few days learning linq and producing json results from my controller in mvc. I am now however stuck on an issue where I wish to rolling sum (cumulative sum) values of Y-Axis data to produce a year to date line chart.

My code at present to produce simple monthly data is as follows:

//Generic Json For Graphs
public JsonResult GetJSONYTD(int kpiID)
{
    var ViewData = 
        (from kpidata in departmentrepo.GetGraphData(kpiID)
         select new DepartmentOverviewDetailsViewModel.GraphJSONViewModel
         {
             XData = kpidata.Year.Year1 + "-" 
                     + kpidata.Month.Real_Month_Int + "-01",
             YData = kpidata.Value
         });

    var ChartData = ViewData.Select(
                        x => new object[] { x.XData, x.YData }).ToArray();

    return Json(ChartData, JsonRequestBehavior.AllowGet);
}

The above produces the following array:

[
 ["2011-10-01",0],
 ["2011-11-01",22],
 ["2011-12-01",22],
 ["2012-1-01",14],
 ["2012-2-01",14.4],
 ["2012-3-01",17.5],
 ["2012-4-01",20.3],
 ["2012-5-01",23.5],
 ["2012-6-01",24.5],
 ["2012-7-01",26.5]
]

I would like to output:

[
 ["2011-10-01",0],
 ["2011-11-01",22],
 ["2011-12-01",44],
 ["2012-1-01",38],
 ["2012-2-01",52.4],
 etc
]

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:53:36+00:00Added an answer on June 11, 2026 at 2:53 pm

    Change your code to:

    //Generic Json For Graphs

    public JsonResult GetJSONYTD(int kpiID)
    {
        var graphData = departmentrepo.GetGraphData(kpiID);
        var ViewData = (from kpidata in graphData
    
                        select new DepartmentOverviewDetailsViewModel.GraphJSONViewModel
                        {
                            XData = kpidata.Year.Year1 + "-" + kpidata.Month.Real_Month_Int + "-01",
                            YData = graphData.Where(x=>x.Date<=kpidata.Date).Sum(x=>x.Value)
                        });
    
        var ChartData = ViewData.Select(x => new object[] { x.XData, x.YData }).ToArray();
    
        return Json(ChartData, JsonRequestBehavior.AllowGet);
    }
    

    The above code will store in YData the sum of all data points that have a data less than or equal to the current date.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have spent several days now researching Hibernate and have several small questions about
I have spent last 3 days until I got gps working on android using
I have spent some time now to solve a problem for which i have
I've spent so much time the last few days trying to work out some
I am new to MySQL from an admin point of view. I have spent
Facebook Connect I have spent a few weeks putting together a basic web site
I just started learning Zend (& OO PHP for that matter), I have spent
I'm in my early days of programming and have one a few applications in
I have been searching for a solution to this issue for a few days
Have spent an hour trying to solve this - but to no avail. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.