Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.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# MS图表控制轴格式化_C#_Winforms_Mschart - Fatal编程技术网

C# MS图表控制轴格式化

C# MS图表控制轴格式化,c#,winforms,mschart,C#,Winforms,Mschart,我正在编写的Winforms应用程序中使用MS图表控件。我显示的散点图的X轴分量是Int64数据,它最终表示UTC时间。我想获取该Int64数据,并在其上执行DataTime.FromFileTimeUTC(theTime).ToString()以显示有意义的最终用户X轴标签 目前,我正在内存数据表中创建另一列,以保存与Int64等效的日期时间,如下所示: dataTable.Columns.Add("mytimestamp"); foreach (DataRow dr in dataTable

我正在编写的Winforms应用程序中使用MS图表控件。我显示的散点图的X轴分量是Int64数据,它最终表示UTC时间。我想获取该Int64数据,并在其上执行DataTime.FromFileTimeUTC(theTime).ToString()以显示有意义的最终用户X轴标签

目前,我正在内存数据表中创建另一列,以保存与Int64等效的日期时间,如下所示:

dataTable.Columns.Add("mytimestamp");
foreach (DataRow dr in dataTable.Rows)
{
   dr["mytimestamp"] = DateTime.FromFileTimeUTC(Convert.ToInt64(dr["theint64val"].ToString()));
}
然后使用“mytimestamp”列作为x轴值。这很好,我可以将x轴标签显示为日期时间值

但是,我不想麻烦地创建列并复制另一列的数据,但我没有找到格式化x轴标签的方法。我想可能错过了这个。我在文档中看到AxisViewChanged事件,并看到如何使用该数据设置图表标题,而不是x轴标签本身

有什么想法吗?

你试过吗

 yourSeries.XValueType = ChartValueType.Time;

我很晚了,但我希望这对其他人有用

一种可能的方法是订阅事件,例如:

void chart1_FormatNumber(object sender, FormatNumberEventArgs e)
{
    if (e.ElementType == ChartElementType.AxisLabels &&
        e.ValueType == ChartValueType.Int64)
    {
        e.LocalizedValue = DateTime.FromFileTimeUtc((long)e.Value).ToShortDateString();
    }
}
由于此事件处理程序是在转换图表的多个元素期间调用的,为了确保仅格式化所需的轴,可以将自定义格式传递给轴标签:

this.chart1.ChartAreas[0].AxisX.LabelStyle.Format = "MyAxisXCustomFormat";
然后在事件处理程序中添加检查:

void chart1_FormatNumber(object sender, FormatNumberEventArgs e)
{
    if (e.ElementType == ChartElementType.AxisLabels &&
        e.ValueType == ChartValueType.Int64 && 
        e.Format == "MyAxisXCustomFormat")
    {
        e.LocalizedValue = DateTime.FromFileTimeUtc((long)e.Value).ToShortDateString();
    }
}

@尼科特克:我提供了一个答案……谢谢,@digEmAll,这很有帮助!