Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.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# 为特定数据点格式化Microsoft图表控件X轴标签_C#_.net_Winforms_User Interface_Charts - Fatal编程技术网

C# 为特定数据点格式化Microsoft图表控件X轴标签

C# 为特定数据点格式化Microsoft图表控件X轴标签,c#,.net,winforms,user-interface,charts,C#,.net,Winforms,User Interface,Charts,在winfow应用程序中,我有一个带有2个图表区域的ms图表。 第一个图表区域包含4个系列(堆叠和条形) 我需要更改某些特定点的X轴标签颜色,但在VS 2010中,我只能更改axislabel文本,而不能更改颜色 有什么方法可以做到这一点吗?在此链接中: 您将发现使用LabelStyle类更改轴的标签。使用LabelStyle.ForeColor属性来更改标签的颜色。我知道这对于OP来说已经太晚了,但是它可能对正在寻找如何执行此操作的其他人有用 自定义标签允许您设置颜色,问题是如果添加一个自定

在winfow应用程序中,我有一个带有2个图表区域的ms图表。 第一个图表区域包含4个系列(堆叠和条形)

我需要更改某些特定点的X轴标签颜色,但在VS 2010中,我只能更改axislabel文本,而不能更改颜色

有什么方法可以做到这一点吗?

在此链接中:


您将发现使用LabelStyle类更改轴的标签。使用LabelStyle.ForeColor属性来更改标签的颜色。

我知道这对于OP来说已经太晚了,但是它可能对正在寻找如何执行此操作的其他人有用

自定义标签允许您设置颜色,问题是如果添加一个自定义标签,则所有标准标签将消失,因此必须为整个轴创建自定义标签,然后为希望不同的轴设置颜色

此代码假定每个X值都需要一个标签。如果有大量X值,则需要调整代码

double offset = 0.5;//Choose an offset that is 1/2 of the range between x values
for (int i = 0; i < chart1.Series[0].Points.Count; i++)
{
    var customLabel = new CustomLabel();
    //NOTE: the custom label will appear at the mid-point between the FromPosition and the ToPosition
    customLabel.FromPosition = chart1.Series[0].Points[i].XValue - offset; //set beginning position (uses axis values)
    customLabel.ToPosition = chart1.Series[0].Points[i].XValue + offset; //set ending position  (uses axis values)
    customLabel.Text = chart1.Series[0].Points[i].XValue.ToString(); //set the text to display, you may want to format this value
    if (i == 3)
    {
    customLabel.ForeColor = Color.Green;//only change the 3rd label to be green, the rest will default to black
    }
    chart1.ChartAreas[0].AxisX.CustomLabels.Add(customLabel);
}
double offset=0.5//选择x值范围的1/2的偏移
对于(int i=0;i
我见过,但该样式适用于整个轴。我必须将x轴标签用红色表示,仅用于系列中的某些点,而不是所有点。Body能帮我吗?这个问题仍然没有答案。