Hide labels on databound chart

5 posts, 0 answers
  1. Derek
    Derek avatar
    118 posts
    Member since:
    Oct 2008

    Posted 26 Nov 2011 Link to this post

    We have a chart in a report that uses datagroupcolumn to break the data into different series.

    Is it possible to remove the series labels? How?
  2. Elian
    Admin
    Elian avatar
    435 posts

    Posted 28 Nov 2011 Link to this post

    Hi Derek,

    Using the DataGroupColumn creates dynamic series and you do not have access to their appearance properties. If you wish to customize the series appearance you should create them with code.

    Best wishes,
    Elian
    the Telerik team

    Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  3. DevCraft banner
  4. Derek
    Derek avatar
    118 posts
    Member since:
    Oct 2008

    Posted 11 Dec 2011 Link to this post

    Creating the graph in codebehind really isn't a viable option. This is a dynamic chart, so I don't know how many combinations of row/column values I will have.

    Is there any way to read the chart items after generation, and turn off or format the labels? Is there any way to apply a 'global' default format to data labels, that would be used for all items regardless of series?

    The chart functionality is *almost* there, but this is a showstopper.
  5. Elian
    Admin
    Elian avatar
    435 posts

    Posted 13 Dec 2011 Link to this post

    Hello Derek,

    There is no reason why you can't create the series dynamically. Here's a sample code that groups data and creates chart:
    void CreateChartSeries()
            {
                var data = new[]{
                            new {Name = "Item 0", Value = 2, Group = 1},
                            new {Name = "Item 1", Value = 1, Group = 1},
                            new {Name = "Item 2", Value = 3, Group = 1},
                            new {Name = "Item 3", Value = 4, Group = 2},
                            new {Name = "Item 4", Value = 8, Group = 2},
                            new {Name = "Item 5", Value = 5, Group = 2},
                            new {Name = "Item 6", Value = 9, Group = 3},
                            new {Name = "Item 7", Value = 4, Group = 3},
                            new {Name = "Item 8", Value = 9, Group = 3},
                            new {Name = "Item 9", Value = 3, Group = 1},
    //we assume that we don't know the structure of the data
                           };
     
                //we already have created chart with styles
                //and properties set as we like
                //just adding the data here
                foreach (var dataItem in data)
                {
                    var series = myChart.Series.GetByName(dataItem.Group.ToString());
                    if (series == null)
                    {
                        series = new ChartSeries(dataItem.Group.ToString());
                        series.Type = ChartSeriesType.Line;
                        series.Appearance.LabelAppearance.Visible = false;
     
                        myChart.Series.Add(series);
                    }
                    var newItem = new ChartSeriesItem(dataItem.Value, dataItem.Name);
                    series.Items.Add(newItem);
                }
            }

    See attached image for result. This is a simple approach to grouping (can be done in different ways, other than using the series name as key).

    Kind regards,
    Elian
    the Telerik team

    Q3’11 of Telerik Reporting is available for download. Register for the What's New in Data Tools webinar to see what's new and get a chance to WIN A FREE LICENSE!

  6. Derek
    Derek avatar
    118 posts
    Member since:
    Oct 2008

    Posted 15 Nov 2012 Link to this post

    Could this approach be used on a chart contained in a report?
Back to Top
DevCraft banner