This is a migrated thread and some comments may be shown as answers.

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

1 Answer 273 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Rong
Top achievements
Rank 1
Rong asked on 12 Aug 2013, 08:43 PM

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

1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 15 Aug 2013, 03:27 PM
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.
Tags
Chart (Obsolete)
Asked by
Rong
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or