gpt4 book ai didi

c# - mvc 5 DataVisualization 绘制错误日期图表

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:34 24 4
gpt4 key购买 nike

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

 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();
}
}

虽然我在表中只有三个值:

enter image description here

我得到了错误的日期:

enter image description here

我正在使用 EF 6.1。无法弄清楚如何才能在 AxisX 上只显示正确的日期。

最佳答案

感谢@Tamwe。我变了

Date = g.Key.Date.ToString() 

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

关于c# - mvc 5 DataVisualization 绘制错误日期图表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36301203/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com