我在折线图中的x轴上显示来自数据库的正确日期时遇到问题。它曾经工作。我提供了一个选项,可以从组合框中选择一个用户,并根据所选用户在折线图中显示数据。然后它走下坡路。费用和收入按时间顺序显示在图表中,但日期不正确。应该是2019年5月,但是是1900年1月。
public void LineChart()
{
if (IndexCBChooseUser != 0)
{
chart2.Series["Wydatki"].Points.Clear();
chart2.Series[0].XValueType = ChartValueType.DateTime;
var ListOfDataExpense = DBaccess.GetOperationWithCategory().Where(x => x.UserId == (IndexCBChooseUser))
.Select(x => new {date = x.Data.Date, price = x.Typ.Equals("wydatek") ? x.Kwota : 0});
var ListOfDataIncome = DBaccess.GetOperationWithCategory().Where(x => x.UserId == (IndexCBChooseUser))
.Select(x => new {date = x.Data.Date, price = x.Typ.Equals("przychod") ? x.Kwota : 0});
chart2.Series[0].Points.DataBind(ListOfDataExpense, "date", "price", "");
chart2.Series[0].XValueType = ChartValueType.DateTime;
chart2.Series[1].Points.DataBind(ListOfDataIncome, "date", "price", "");
chart2.Series[1].XValueType = ChartValueType.DateTime;
}
else
{
chart2.Series["Wydatki"].Points.Clear();
chart2.Series[0].XValueType = ChartValueType.DateTime;
var ListOfDataExpense = DBaccess.GetOperationWithCategory()
.Select(x => new { date = x.Data.Date, price = x.Typ.Equals("wydatek") ? x.Kwota : 0 });
var ListOfDataIncome = DBaccess.GetOperationWithCategory()
.Select(x => new { date = x.Data.Date, price = x.Typ.Equals("przychod") ? x.Kwota : 0 });
chart2.Series[0].Points.DataBind(ListOfDataExpense, "date", "price", "");
chart2.Series[0].XValueType = ChartValueType.DateTime;
chart2.Series[1].Points.DataBind(ListOfDataIncome, "date", "price", "");
chart2.Series[1].XValueType = ChartValueType.DateTime;
}
}
什么可能导致此问题?