Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC5数据可视化绘制错误日期_C#_Asp.net Mvc_Linq_Charts - Fatal编程技术网

C# MVC5数据可视化绘制错误日期

C# MVC5数据可视化绘制错误日期,c#,asp.net-mvc,linq,charts,C#,Asp.net Mvc,Linq,Charts,我正在使用以下内容生成图表: private Byte[] myChart() { var query = from o in db.charttest group o by new { o.Date, o.Value } into g select new { Value =

我正在使用以下内容生成图表:

 private Byte[] myChart()
    {
        var query = from o in db.charttest
                    group o by new { o.Date, o.Value }
             into g
                    select new
                    {
                        Value = g.Key.Value,
                        Date = g.Key.Date,
                        Number = g.Count()
                    };
        var chart = new Chart
        {
            Width = 700,
            Height = 450,
            RenderType = RenderType.ImageTag,
            AntiAliasing = AntiAliasingStyles.All,
            TextAntiAliasingQuality = TextAntiAliasingQuality.High
        };
        chart.Titles.Add("Summary");
        chart.Titles[0].Font = new Font("Arial", 16f);
        chart.ChartAreas.Add("");
        chart.ChartAreas[0].AxisX.Title = "Date";
        chart.ChartAreas[0].AxisY.Title = "Value";
        chart.ChartAreas[0].AxisX.TitleFont = new Font("Arial", 12f);
        chart.ChartAreas[0].AxisY.TitleFont = new Font("Arial", 12f);
        chart.ChartAreas[0].AxisX.LabelStyle.Font = new Font("Arial", 10f);
        chart.ChartAreas[0].AxisX.LabelStyle.Angle = -90;
        chart.ChartAreas[0].BackColor = Color.White;
        chart.Series.Add("");
        chart.Series[0].ChartType = SeriesChartType.Column;
        foreach (var q in query)
        {
            var Name = q.Value;
            var Day = q.Date;
             chart.Series[0].Points.AddXY(Day, Name);
        }
        using (var chartimage = new MemoryStream())
        {
            chart.SaveImage(chartimage, ChartImageFormat.Png);
            return chartimage.GetBuffer();
        }
    }
虽然表中只有三个值:

我有错误的日期:


我使用的是EF6.1。无法确定如何在AxisX上仅显示正确的日期。

多亏了@Tamwe。我变了

Date = g.Key.Date.ToString() 

现在,图表在X轴上显示正确的日期。

您使用的是哪些图表?我使用的是DataVisualization.Charting。如果您将X值转换为字符串,您将获得标有日期的3个数据点。但是请注意,字符串不能像DateTime那样在x轴上排列/排序,因此如果首先添加最新日期,则第一个数据点将标有最新日期。