2

我正在使用基于具有输出代码 javascript 的 C# 代码的 Dotnet Highchart。 点网高图

这几乎是我的图表的样子:

图表

我正在使用我的数据库中的数据通过使用 LINQ 查询来提供此图表数据。

我的实体中有一个“完成日期”列,我需要使用 datepicker 创建两个文本框,以便用户可以选择完成日期的开始和结束日期。然后用户应该能够单击提交按钮,然后图表应该更新并显示两个日期之间的统计数据。我有完整的 LINQ 查询

这是我要使用的 LINQ 查询:

public List<CoreValueAndAverageGrade> GetAverageGradeForAllCoreValues(DateTime startDate, DateTime endDate)
        {



            return db.CoreValue
                .Where(coreValue => coreValue.CoreValueQuestion
                    .Any(coreValueQuestion => coreValueQuestion.SubjectType.Ignored_Statistic == false))
                .Select(coreValue => new CoreValueAndAverageGrade
                {
                    CoreValue = coreValue,
                    AverageGrade = coreValue.CoreValueQuestion
                        .Where(coreValueQuestion => coreValueQuestion.SubjectType.Ignored_Statistic == false)
                        .Average(coreValueQuestion => coreValueQuestion.SelectedQuestions
                            .Where(selectedQuestion => selectedQuestion.GoalCardQuestionAnswer != null
                                && selectedQuestion.GoalCardQuestionAnswer.Grade.HasValue

                            && selectedQuestion.GoalCard.Completed_Date >= startDate
                            && selectedQuestion.GoalCard.Completed_Date <= endDate
                                )
                            .Average(selectedQuestion => selectedQuestion.GoalCardQuestionAnswer.Grade.Value))
                })
                .ToList();
        }

这是我的视图模型

 public class OfficeStatisticNKIViewModel
    {
        public DateTime StartDate { get; set; }
        public DateTime EndDate { get; set; }
    }

在我的 GET 操作方法中,我有以下代码:

public ActionResult OfficeStatistic()
{
    {
       OfficeStatisticNKIViewModel model = new OfficeStatisticNKIViewModel();
       model.EndDate = DateTime.Now;
       model.StartDate = DateTime.Now;
        var averageGrades = OfficeStatisticRepository.GetAverageGradeForAllCoreValues(model.StartDate, model.EndDate);

        var dataItems = (averageGrades.Select(averageGrade => averageGrade.AverageGrade).ToArray());
        Data data = new Data(
            dataItems.Select(y => new Point {Color = GetBarColour(y), Y = y}).ToArray());


        Highcharts chart1 = new Highcharts("Chart")
         .SetXAxis(new XAxis { Categories = averageGrades.Select(averageGrade => averageGrade.CoreValue.Name).ToArray() })
         .SetYAxis(new YAxis { Min = 0, Max = 10, TickInterval = 1, Title = new YAxisTitle { Text = "Betygskalan" } })
         .SetSeries(new Series {  Data = data, Name = "Snittbetyg" })
         .SetLegend(new Legend { Enabled = false })
         .SetTitle(new Title { Text = "Örebro Statistik", })
         .InitChart(new Chart { DefaultSeriesType = ChartTypes.Column });


        return View(new Container(new[] { chart1 }));

    }

问题是我不知道如何执行发布操作方法,图表需要使用新的统计信息进行更新,我需要某种 ajax 还是可以在服务器端执行此操作?

非常感谢任何帮助或提示!

提前致谢!

4

1 回答 1

0

http://dotnethighcharts.codeplex.com/discussions/350721/

于 2012-07-31T20:45:13.793 回答