我正在尝试显示日期并将其恢复到 Labels = strings
,
但是我在行 list.Add((string)myReader["Date"]);
这是我的代码:
con.Open();
myReader = cmdDB.ExecuteReader();
List<string> list = new List<string>();
while (myReader.Read())
{
list.Add((string)myReader["Date"]);
}
string[] strings = list.Select(x => x.ToString()).ToArray();
cartesianChart1.AxisX.Add(new Axis
{
Title = "Date",
Labels = strings
});
cartesianChart1.AxisY.Add(new Axis
{
Title = "Sales",
LabelFormatter = value => value.ToString()
});
有什么解决办法吗?谢谢你!附言我正在使用 LiveCharts 和 MySQL。
最佳答案
你可以这样试试
list.Add(myReader["Date"].ToString());
如果需要,您还可以在 ToString(dd-MM-yyyy) using Custom Date and Time Format Strings 中对日期应用格式
关于c# - 无法将类型为 'System.DateTime' 的对象转换为类型 'System.String'。 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42524639/