Code behind TooltipAppearance.DataFormatString

4 posts, 0 answers
  1. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 22 May 2015 Link to this post

    I am needing to set the code behind TooltipAppearance DataFormatString. 

    I have not had much success with the documentation, I am hoping someone else has had a similar issue.



    <telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Height="400px" Width="480px" CssClass="fb-sized" OnPreRender="RadHtmlChart1_PreRender">
                           <telerik:PieSeries DataFieldY="TypeCount" ExplodeField="IsExploded" NameField="Area">
                               <LabelsAppearance DataFormatString="{0}">
                               <TooltipsAppearance Color="White">
                                   #=dataItem.Area#<br />#=dataItem.TypeCount#


    public void buildChart()
           PieSeries pieSeries1 = new PieSeries();
           pieSeries1.Name = "Chart";
           pieSeries1.LabelsAppearance.Visible = false;
           pieSeries1.TooltipsAppearance.Color = System.Drawing.Color.White;
           pieSeries1.TooltipsAppearance.DataFormatString = "???????????";
           // What I need in the template is the series name and then the value  somethin like this:  #=dataItem.Name#<br />#=dataItem.Valu#
           pieSeries1.SeriesItems.Add(10, Color.Yellow, "Student");
           pieSeries1.SeriesItems[0].Visible = false;
           pieSeries1.SeriesItems.Add(20, Color.Red, "Staff");
           pieSeries1.SeriesItems.Add(50, Color.Green, "Room");
           pieSeries1.SeriesItems.Add(20, Color.Purple, "Transfer");
       protected void Page_Load(object sender, EventArgs e)

  2. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 22 May 2015 Link to this post

    Here is a revised code listing, still can't seem to get the tooltip to do what I want though.  

    protected void Page_Load(object sender, EventArgs e)
              var data = VoidLoadData();
              var result = RadHtmlChart1.PlotArea.Series;
              var item = result[0] as PieSeries;
              int index = 0;
              User user = (User)Session["currentUser"];
              var tagDistributionsService = new TagDistributionsService(user,
                      new UserPreferenceService(new UserPreferenceRepository()));
              var legendPreferences = tagDistributionsService.GetUserLegendSettings();
              foreach (chartDistribution distribution in data)
                  Color currentColor = index == 0
                    ? Color.Red
                    : index == 1 ? Color.Yellow : index == 2 ? Color.Purple : Color.Orange;
                  PieSeriesItem seriesItem = new PieSeriesItem(distribution.TypeCount, currentColor, distribution.Area);
                  foreach (var legend in legendPreferences)
                      if (legend.Legend == distribution.Area)
                          item.SeriesItems[index].Visible = false;
                          item.DataFieldTooltip = "CountType";
                          item.TooltipsAppearance.ClientTemplate = "#=dataItem.Area#<br />#=dataItem.TypeCount#";
                  index += 1;

  3. DevCraft R3 2016 release webinar banner
  4. Wired_Nerve
    Wired_Nerve avatar
    163 posts
    Member since:
    Oct 2007

    Posted 22 May 2015 in reply to Wired_Nerve Link to this post

    I think I might have gotten it finally.
    I was looking at giving up on how to do the tooltip and began looking at opening a radwidow from the client side using the onSeriesClicked javascript event.  I noticed the event used two arguements...  args.value  and args.category
    //alert("You clicked on a series item with value '" + args.value + "' from category '" + args.category + "'.");

    So I updated the template to use this instead:
              <ClientTemplate>  #=category#<br />  #=value# </ClientTemplate>

    That worked.  all of the documentation said I should be using dataItem.Area and dataItem.CountType since my datasource defined them as that... grumble grumble...
  5. Danail Vasilev
    Danail Vasilev avatar
    1476 posts

    Posted 26 May 2015 Link to this post

    Hello Warren,

    I have already replied to the support ticket that was opened by you, so I paste my answer for the rest of the community here:

    Please find my comments and suggestions below:

        - The template should be defined in the TooltipsAppearance.ClientTemplate property and not in the DataFormatString one. You can choose to use either one.
        - If you want to display custom values in the tooltips and labels you should do the following:
            1) Data bind the chart.
            2) Define a template.
            3) Use the dataItem object to access data source fields inside the template.
        - If, however, the chart is not a data bound but created programmatically you can create a data table data source programmatically and bind it to the chart.
        - You can use the same property and tag names from the markup for the programmatic creation of the chart as well.

    More information regarding using client templates is available in the below resources:
    More information regarding the DataFormatString property is available here :
    Let me know if you need any assistance on this regard.

    Danail Vasilev
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top