Hi,
I would like to change the color of the Axis line, but when I set the BorderColor, I get a border around the label that matches the color I am setting for the Axis line. I don't want a border around the label, I just want to change the color of the line. How do I do that?
This is the code: linearAxis1.BorderColor = System.Drawing.Color.FromArgb(((int)(((byte)(52)))), ((int)(((byte)(143)))), ((int)(((byte)(142)))));
Laura
7 Answers, 1 is accepted
Thank you for writing.
The axis children are inheriting the border color and in this case you must set their border color as well:
foreach (var item in verticalAxis.Children){ item.BorderColor = Color.Transparent;}Please let me know if there is something else I can help you with.
Regards,
Dimitar
Telerik
Thank you Dimitar! This worked perfectly, though I did have to change it just slightly to also change the backcolor of the item, then all worked well.
foreach (var item in verticalAxis.Children)
{
item.BorderColor = Color.Transparent;
item.BackColor = Color.Transparent;
}
I am glad I could be of help. Let us know if you have any other questions.
Regards,
Dimitar
Telerik
Cycling the Axis.Children works if your axis are static, if you however are sending live data to you chart and your axis change, it puts all the borders back around the labels again. I tried cycling the children after changing the min and max values, but no luck in keeping the borders around the labels hidden.
You can use custom renderer for this case. Here is a sample implementation:
public class CustomCartesianRenderer : CartesianRenderer{ public CustomCartesianRenderer(CartesianArea area) : base(area) { } protected override void Initialize() { base.Initialize(); for (int i = 0; i < this.DrawParts.Count; i++) { AxisLabelDrawPart part = this.DrawParts[i] as AxisLabelDrawPart; if (part != null && part.Element is CategoricalAxis) { this.DrawParts[i] = new MyAxisLabelDrawPart((CategoricalAxis)part.Element, this); } } }}class MyAxisLabelDrawPart : AxisLabelDrawPart{ public MyAxisLabelDrawPart(Axis axis, IChartRenderer renderer) : base(axis, renderer) { } protected override void DrawNoneAndMultiLineLabelElements() { foreach (var item in this.Element.Children) { item.BorderWidth = 0; } base.DrawNoneAndMultiLineLabelElements(); }}The default renderer can be changed in the CreateRenderer event handler:
void radChartView1_CreateRenderer(object sender, ChartViewCreateRendererEventArgs e){ e.Renderer = new CustomCartesianRenderer(e.Area as CartesianArea);}I hope this will be useful. Let me know if you have additional questions.
Regards,
Dimitar
Progress Telerik
Not to sound negative by any means, but this seems excessive to be able to remove the borders on labels. Based on my understanding, are inherited from the axis border.
Suggested upgrade idea, would resolve my issue here.
HorizontalAxis.LabelBorder.Visible = False
VerticalAxis.LabelBorder.Visible = False
This is a good suggestion and this is why I have logged a feature request for this in our Feedback Portal. You can track its progress, subscribe for status changes and add your comment to it here. I have also updated your Telerik Points.
Should you have any other questions do not hesitate to ask.
Regards,
Dimitar
Progress Telerik
