BoldDeskWe are launching BoldDesk on Product Hunt soon. Learn more & follow us.
Hello, could you advise how to add red vertical line annotation as per attached? (target line)
Also I'd like to invert the legend order of series so that it shows the same order as displayed in chart..
Thank you
Hi Jacob,
Query 1: Add vertical line annotation as per image.
The Vertical line can only be achieved by using the StripLine property and for the stripline you have to define start and end value as shown in the code snippet below.
If both start and end values are same then stripline will not be displayed, because the stripline width is equal to the difference of start and end value.
ChartStripLine stripLine = new ChartStripLine(); stripLine.Vertical = false; stripLine.Enabled = true; stripLine.Start = 420; stripLine.End = 421; stripLine.Text = ""; stripLine.ZOrder = ChartStripLineZorder.Over; stripLine.Interior = new BrushInfo(Color.Red); this.chartControl1.PrimaryXAxis.StripLines.Add(stripLine); |
Query 2: Inverse the legend Item order.
The order of the legend item can be inversed using the FilterItems event. In this event will iterate the Legend Items in reverse order and add it to the item again as shown in the code snippet below.
private void InitializeComponent() { this.chartControl1.Legend.FilterItems += Legend_FilterItems; } |
private void Legend_FilterItems(object sender, ChartLegendFilterItemsEventArgs e) { ChartLegendItemsCollection items = new ChartLegendItemsCollection(); for (int i = e.Items.Count - 1; i >= 0; i--) items.Add(e.Items[i]);
e.Items = items; } |
I have attached a demo sample based on your requirement for reference please check and let us know if need any further assistance.
Regards,
Moneeshram
Hi Moneeshram,
This is great! Thanks!
The only problem I am having is with implementing the 2nd query in VB.NET
Do you have working example in VB.net on how to reverse the legend?
Thank you so much for time and patience
Me.chartControl1.Legend.FilterItems +=New LegendFilterItemsEventHandler(Legend_FilterItems)
Private Sub Legend_FilterItems(ByVal sender As Object, ByVal e As ChartLegendFilterItemsEventArgs)
'This creates an new instance of the ChartLegendItemCollection
Dim item As ChartLegendItemsCollection = New ChartLegendItemsCollection()
Dim i As Integer
For i = e.Items.Count - 1 To 0 Step i - 1
item.Add(e.Items(i))
Next
e.Items =item
End Sub
Query: How to reverse the legend in VB.Net?
We can reverse the legend order in the VB by using the code snippet as shown below.
Me.chartControl1.Legend.FilterItems +=New LegendFilterItemsEventHandler(Legend_FilterItems)
Private Sub Legend_FilterItems(ByVal sender As Object, ByVal e As ChartLegendFilterItemsEventArgs) 'This creates an new instance of the ChartLegendItemCollection Dim item As New ChartLegendItemsCollection()
For i As Integer = e.Items.Count - 1 To 0 Step -1 item.Add(e.Items(i)) Next
e.Items = item
End Sub |
Also please check the below attached UG document for reference and let us know if need any
further assistance.
Regards,
Moneeshram
Hi Moneeshram,
This is exactly what I've tried, however I am a little embarrassed as I cannot get it to work.. I am just learning to code.
I get the following errors and even when trying to follow the advice on the error message I still cannot structure the code properly to make it work.
We would like to inform you that the issue is raised because in VB you should not trigger the event as in C#, as shown in the given image. In VB, you have to trigger the handler as shown in the code snippet below.
Private Sub InitializeComponent() 'ChartControl1 code . . . AddHandler Me.ChartControl1.Legend.FilterItems, AddressOf Legend_FilterItems End Sub
Private Sub Legend_FilterItems(sender As Object, e As ChartLegendFilterItemsEventArgs) Dim item As New ChartLegendItemsCollection()
For i As Integer = e.Items.Count - 1 To 0 Step -1 item.Add(e.Items(i)) Next
e.Items = item End Sub |
Please check and let us know if you need any further assistance.
Regards,
Moneeshram.
Thank you, issue resolved!
Thanks so much!
Hi Jakub,
We are glad to know that the reported problem has been resolved. Please let us know if you have any further queries on this. We are happy to help.
Regards,
Preethi R