Search code examples
activexteechart

Series Mark Style Change


There is a new requirement from our client. they want the mark to display the value as well as percentage. But currently there is no Option for the same in the Series Marks property page. Is there any work around by which we can show Value along with percentage.

Thanks Akshay


Solution

  • You have two options:

    1. Using smsLabelPercentValue, for example:

      TChart1.Series(0).Marks.Style = smsLabelPercentValue
      
    2. Customize marks text in the OnGetSeriesMark event, for example:

      Dim sum As Double
      
      Private Sub Form_Load()
          TChart1.Series(0).FillSampleValues
          'TChart1.Series(0).Marks.Style = smsLabelPercentValue
      
          sum = 0
      
          For i = 0 To TChart1.Series(0).Count
              sum = sum + TChart1.Series(0).YValues.value(i)
          Next
      End Sub
      
      Private Sub TChart1_OnGetSeriesMark(ByVal SeriesIndex As Long, ByVal ValueIndex As Long, MarkText As String)
          Dim value As Double
          Dim percent As Double
      
          value = TChart1.Series(SeriesIndex).YValues.value(ValueIndex)
          percent = (value / sum) * 100
      
          MarkText = CStr(value) & " " & CStr(percent) & "%"
      End Sub 
      
    3. Use a hybrid solution, manually parsing MarkText argument with smsLabelPercentValue in OnGetSeriesMark event.