Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
195
Solution on Customize Labels on Ultrachart
posted

Thought this might be of help to those of you who are want to customize your Y-Axis labeling on your charts. (note: this solution is based off of the article knowledgebase regarding customize labeling that Infragistics has on their site--gotta give credit where credit is due--I just expanded and tailored it my needs) Just to illustrate:

Y-Axis DATA VALUES Label Before:
$1,000,000
$100,000
$10,000
$1,000

Y-Axis DATA VALUES Label After:
$1M
$100K
$10K
$1K

Now that takes up less space and is much more readable. Now--onto the code!

Public Class MyLabelRenderer

Implements IRenderLabel

Public Overloads Function ToString(ByVal context As Hashtable) _

As String Implements IRenderLabel.ToStringSelect Case CDbl(context("DATA_VALUE"))

 

Case Is < -999

Return CStr(context("DATA_VALUE")).Substring(0, 4) & "K"

Case Is < -10000

Return CStr(context("DATA_VALUE")).Substring(0, 3) & "K"

Case Is < -100000

Return CStr(context("DATA_VALUE")).Substring(0, 2) & "K"

Case Is < -1000000

Return CStr(context("DATA_VALUE")).Substring(0, 1) & "K"

Case Is < 1000

Return CStr(context("DATA_VALUE"))

Case Is < 10000

Return CStr(context("DATA_VALUE")).Substring(0, 1) & "K"

Case Is < 100000

Return CStr(context("DATA_VALUE")).Substring(0, 2) & "K"

Case Is < 1000000

Return CStr(context("DATA_VALUE")).Substring(0, 3) & "K"

Case Is < 10000000

Return CStr(context("DATA_VALUE")).Substring(0, 1) & "M"

Case Is < 100000000

Return CStr(context("DATA_VALUE")).Substring(0, 2) & "M"

End Select

 

End Function

End Class

 

Private Sub Customize_Labels_Using_the_IRenderLabel_Interface_Load( _

ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles MyBase.Load

Me.YourChartNameHere.Axis.Y.Labels.ItemFormatString = "<MY_VALUE>"

Dim MyLabelHashTable As New Hashtable()MyLabelHashTable.Add("MY_VALUE", New MyLabelRenderer())

YourChartNameHere.LabelHash = MyLabelHashTable

End Sub


Now, I only chose to customize the Y axis because that usually contains the data values (which is what I'm interested in). You easily modify the code above to include changes in the X axis as well.

 Happy coding!