Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Private chartDT As DataTable
Private showingCustomisedLabels As Boolean = False
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
'incase we're on 64 bit OS
Try
' Create some data
chartDT = New System.Data.DataTable
chartDT.Columns.Add("Person", GetType(String))
chartDT.Columns.Add("TotalTime", GetType(Long))
chartDT.Rows.Add("Fred", 45678)
chartDT.Rows.Add("Bob", 94561)
chartDT.Rows.Add("Jim", 64576)
chartDT.Rows.Add("Alex", 83457)
' initialise the chart
Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Chart1.Series(0).ChartType = SeriesChartType.Bar
Chart1.Series(0).XValueMember = "Person"
Chart1.Series(0).YValueMembers = "TotalTime"
Chart1.Series(0).Label = "#AXISLABEL"
' add the data to the chart
Chart1.DataSource = chartDT
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
Private Sub CustomiseYaxis()
Dim yAxis As Axis = Chart1.ChartAreas(0).AxisY
yAxis.CustomLabels.Clear()
Dim labelInterval = yAxis.LabelStyle.Interval
For value = yAxis.Minimum To yAxis.Maximum Step labelInterval
Dim ts = TimeSpan.FromSeconds(value)
yAxis.CustomLabels.Add(value - labelInterval / 2, _
value + labelInterval / 2, _
String.Format("{0}h:{1}m:{1}s", ts.Days * 24 + ts.Hours, ts.Minutes, ts.Seconds))
Next
End Sub
Private Sub Chart1_Customize(sender As Object, e As System.EventArgs) Handles Chart1.Customize
If Not showingCustomisedLabels Then
CustomiseYaxis()
showingCustomisedLabels = True
End If
End Sub
End Class