在.NET图表只能使用自定义标签在X轴 [英] Use only custom label in X-axis in .NET chart
问题描述
我正在与周X轴的时间间隔在C#中的.NET线图。对于我的项目,我只希望使用自定义标签,但现在我还是想网格线。 ?有谁知道一个方法来隐藏默认的X轴标签,同时仍保持自定义标签
I'm making a .NET line graph in C# with an X-axis interval of weeks. For my project, I only want to be using the custom label, but for now I still want the gridlines. Does anyone know a way to hide the default X-Axis labels while still keeping the custom labels?
我试过这样:
Chart4.ChartAreas[0].AxisX.LabelStyle.Enabled = false;
最明显的结果是,有没有应用的标签,这不是我所试图做的。
The obvious result is that there were no labels applied, which is not what I was trying to do.
编辑:
产生原始行的代码是这样的:
The code for generating the original rows was this:
Chart4.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "M";
和自定义标签的代码是这样的:
And the code for the custom label was this:
int month = XValues[0].Month;
var XAxis = Chart4.ChartAreas[0].AxisX;
DateTime StartMonthPos = XValues[0];
DateTime EndPos = new DateTime();
foreach (DateTime Date in XValues)
{
EndPos = Date;
if (Date.Month != month)
{
Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None);
StartMonthPos = Date;
}
month = Date.Month;
}
XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 1, LabelMarkStyle.None);
图表看起来是这样的:
The chart looks like this:
和它看起来应该是这样的:
And it should look like this:
推荐答案
好吧,我看着标签
在控制MSDN 的。为了使自定义标签将代替正常的标签,我设置了的rowIndex
参数 0
,更换默认的标签行。自定义行的最终代码看起来是这样的:
Alright, I looked into Label
controls on MSDN. In order to make the custom label appear in place of the normal label, I set the RowIndex
parameter to 0
, replacing the default label row. The final code for the custom rows looked like this:
int month = XValues[0].Month;
var XAxis = Chart4.ChartAreas[0].AxisX;
DateTime StartMonthPos = XValues[0];
DateTime EndPos = new DateTime();
foreach (DateTime Date in XValues)
{
EndPos = Date;
if (Date.Month != month)
{
Chart4.ChartAreas[0].AxisX.CustomLabels.Add(StartMonthPos.ToOADate(),
EndPos.ToOADate(), StartMonthPos.ToString("MMMM"), 0, LabelMarkStyle.None);
StartMonthPos = Date;
}
month = Date.Month;
}
XAxis.CustomLabels.Add(StartMonthPos.ToOADate(), EndPos.ToOADate(),
StartMonthPos.ToString("MMMM"), 0, LabelMarkStyle.None);
这篇关于在.NET图表只能使用自定义标签在X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!