数据可视化日期时间轴季度格式



我正在使用.NET数据可视化库来创建一些图表。数据都是基于时间序列的(即,x 轴是日期(。

我知道我可以使用自定义日期和时间格式字符串来格式化 x 轴标签(从 http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx 开始格式化(,通过

AxisX.LabelStyle.Format = "yyyy"

命令。

但是,如果我想通过 .NET 库中未提供的自定义函数设置标签的格式,该怎么办?

更具体地说,是否可以使用日期的季度来格式化 x 轴标签?换句话说:

  • 1-3月:第一季度
  • 4月至6月:第二季度
  • 7月至9月:第三季度
  • 10月至12月:第四季度

提前感谢!

创建自己的函数并返回自定义标签并将它们单独分配给数据点

例如:-

string lblText = CustomLabelFunction(Chart1.Series["Default"].Points[0]);
Chart1.Series["Default"].Points[0].AxisLabel = lblText;

为了进一步帮助任何人,我更喜欢使用列表并将列表绑定到图表。

List<string> xValues = new List<string>() { 
"Jan-Mar: Q1", "Apr-Jun: Q2", "Jul-Sep: Q3", "Oct-Dec: Q4" }; 
List<int> yValues = new List<int>() { 2, 8, 4, 21};
// Assign the data to the chart
Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);

有关信息,这将被覆盖:

Chart1.Series["Default"].XValueType = ChartValueType.Date; 

最新更新