How can I add customized tooltip on individual sector of a pie chart in the code behind?

Thread is closed for posting
2 posts, 0 answers
  1. Rong
    Rong avatar
    1 posts
    Member since:
    Dec 2012

    Posted 12 Aug 2013 Link to this post

    Hi,
    I need to display customized tooltips on individual sectors of a pie chart. How can I do it in the code behind? Because I also need to customize the background color of the pie chart, I have to dynamically generate pie series in the code behind.
    My code snippet is attached.

    Thanks,

    Rong

        Private Sub LoadAppropriationForAllPrograms()
            lblChrtHeader.Text = "Appropriation by Program"
            Dim budgetFund As New BudgetBookBAL.BudgetBook
            Dim fundDT As New DataTable
            Dim seriesColor As New BudgetBookBAL.StaticColors
            chrtProgram.PlotArea.Series.Clear()
           

            fundDT = budgetFund.GetAppropriationForAllPrograms()

            Dim chartData As New Telerik.Web.UI.PieSeries
            chartData.StartAngle = "90"
            chartData.LabelsAppearance.Position = Telerik.Web.UI.HtmlChart.PieLabelsPosition.Circle
            chartData.LabelsAppearance.DataFormatString = "${0}M"

           
            Dim total As Decimal = 0D
            For Each row As DataRow In fundDT.Rows
                total = CDec(row("TOT_BUDGET")) + total
            Next

            Dim index As Integer = 0
            For Each row As DataRow In fundDT.Rows
                Dim chartSeries As New Telerik.Web.UI.SeriesItem

                Dim pct As Decimal = 0D
                If total > 0 Then
                    pct = CDec(row("TOT_BUDGET")) / total * 100
                End If

                chartSeries.BackgroundColor = seriesColor.GetColor(index)
                Dim desc As String = row("PROG_NAME").ToString + " - $" + CDec(row("TOT_BUDGET")).ToString() + "M (" + pct.ToString("F1") + "%)"

                chartSeries.YValue = CDec(row("TOT_BUDGET"))
                chartSeries.Name = desc
                'chartSeries.TooltipValue = desc
                chartData.Items.Add(chartSeries)
                index += 1
            Next
            chrtProgram.Legend.Appearance.Position = Telerik.Web.UI.HtmlChart.ChartLegendPosition.Right
     
            chrtProgram.PlotArea.Series.Add(chartData)
            chrtProgram.DataBind()
        End Sub

  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 15 Aug 2013 Link to this post

    Hello Rong,

    ToolTips for individual Series Items can only be achieved through the ClientTemplates functionality which requires the RadHtmlChart to be bound to a datasource. You can find such an example in HtmlChart - Client Templates for Series Labels and Tooltips online demo.

    Regarding you question about the colors of the SeriesItems, you can use the ColorField property exposed by the particular Series that references field from the datasource that contains the colors. Such an example can be found in HtmlChart - Chart Element Customization and HtmlChart - Client-side Binding online demos.

    Should you need further assistance on this regard, please feel free to contact us again.

    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top