FlexChart Data Labels

Posted by: aroblesv on 25 April 2024, 7:11 am EST

  • Posted 25 April 2024, 7:11 am EST

    Dear support team,

    I’m using the following code to add DataLabels to FlexChart (vb.net 6.0), but this will add labels to all data points. Is there a way to add labels to specific points? Also, as I understand, there is no Interaction Actions menu as in old C1Chart, so is it possible to add zoom in/out and pan interactions to FlexChart?

    Regards,

    [code]'Set chart’s DataLabels value

    linfluenciaR_806.chart1_806.DataLabel.Content = “{y}”

    'Set template string to create custom content for data labels

    linfluenciaR_806.chart1_806.DataLabel.Content = “{value}”

    'Set chart’s DataLabels position

    linfluenciaR_806.chart1_806.DataLabel.Position = LabelPosition.Auto

    'Set to show data labels borders

    linfluenciaR_806.chart1_806.DataLabel.Border = True

    'Style data labels

    linfluenciaR_806.chart1_806.DataLabel.Style.Font = New Font(FontFamily.GenericSansSerif, 8, FontStyle.Regular)

    linfluenciaR_806.chart1_806.DataLabel.BorderStyle.StrokeColor = Color.Black

    linfluenciaR_806.chart1_806.DataLabel.BorderStyle.FillColor = Color.White[/code]

  • Posted 25 April 2024, 7:47 pm EST

    Hello,

    As of now, there is no direct way to set the label for each item individually but you can handle the LabelRendering event of FlexChart to hide the labels based on different conditions.

    Please find the attached sample implementing the same.

    WindowsFormsApp6.zip

    >>so is it possible to add zoom in/out and pan interactions to FlexChart?

    Please see the following documentation link demonstrating the same:

    https://developer.mescius.com/componentone/docs/win/online-flexchart/zoom.html

    Regards,

    Prabhat Sharma.

  • Posted 29 April 2024, 3:16 am EST

    Hello Prabhat Sharma,

    Thanks for your reply. Could you please provide example in visual basic. I haven’t been able to make the code work.

    Regards,

  • Posted 29 April 2024, 2:05 pm EST

    Hello,

    Please find the vb.net version of the last attached sample below:

    FlexChartDataLabels_VB.zip

    Regards,

    Prabhat Sharma.

  • Posted 2 May 2024, 4:20 am EST

    Hello Prabhat Sharma,

    Thanks a lo for the example. Code is now working as expected. Is it possible to change DataLabel.BorderStyle.FillColor property for a specific label using LabelRendering event?

    For a set of data points, we would like to highlight with a different color labels for maximum and minimum values.

    Regards,

  • Posted 3 May 2024, 1:15 am EST

    Hi Alfredo,

    Considering your use-case, you first need to determine the smallest and largest values of the data label bound property. This information can be found using the FlexChart’s DataSource.

    Then, use the FlexChart’s LabelRendering event to draw a border around the desired labels using RenderDataLabelEventArgs.Graphics property as shown in the following code:

    Private Sub FlexChart1_LabelRendering(sender As Object, e As RenderDataLabelEventArgs)
         If e.Text = minVal.ToString() Then
             Dim s As SizeF = e.Graphics.MeasureString(e.Text, FlexChart1.Font)
             Dim rectangle As New Rectangle(New Point(CInt(e.Point.X), CInt(e.Point.Y)), New Size(CInt(s.Width), CInt(s.Height)))
             e.Graphics.DrawRectangle(New Pen(Color.Red), rectangle)
         End If
         If e.Text = maxVal.ToString() Then
             Dim s As SizeF = e.Graphics.MeasureString(e.Text, FlexChart1.Font)
             Dim rectangle As New Rectangle(New Point(CInt(e.Point.X), CInt(e.Point.Y)), New Size(CInt(s.Width), CInt(s.Height)))
             e.Graphics.DrawRectangle(New Pen(Color.Green), rectangle)
         End If
     End Sub

    Kindly refer to the attached sample for full implementation.

    FlexChartDataLabels_VB_Mod.zip

    Thanks & Regards,

    Aastha

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels