0

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

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

AxisX.LabelStyle.Format = "yyyy"

命令。

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

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

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

提前致谢!

4

2 回答 2

1

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

例如:-

string lblText = CustomLabelFunction(Chart1.Series["Default"].Points[0]);
Chart1.Series["Default"].Points[0].AxisLabel = lblText;
于 2012-05-22T20:52:59.357 回答
0

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

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; 
于 2013-11-13T10:06:52.013 回答