我正在尝试显示日期并将其恢复到 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/
相关文章:
c# - 在 NSubstitute 中使用 IEnumerable 设置参数匹配器
spring-mvc - 如何在应用程序中使用 "RestController"和 "Control
python - Django makemessages 写假文件
php - 所有链接都重定向到 localhost/dashboard/with codeignit
spring-boot - 将所有 Zuul 代理请求动态重新路由到单个 URL
indexing - solr 的 WSO2 API 管理器问题
php - laravel blade 使用 substr 方法禁用转义