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

Stacked bar chart gets clipped

5 Answers 103 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ralph
Top achievements
Rank 1
Ralph asked on 16 Dec 2011, 02:04 AM
I have a stacked bar chart where some of the bars far exceed the automatically generated Y-axis maximum (see attached "clipped stacked bar chart.jpg").

The data comes from an ObservableCollection of a domain object with five floats( called Series1 through Series5). I tried modifying the height of the chart in the completed event. I'm not sure how understandable the partially scrubbed code is, but here is the event and two methods called in the call stack.
        void GetViewCompleted(object sender, GetViewCompletedEventArgs e)
        {
            txtUnAssignedMsg.Visibility = Visibility.Collapsed;
            SetChart("MyXThing", Y1, Y2, Y3, Y4, Y5);
            if (e.Result.Count > 0)
            {
                radChart1.ItemsSource = e.Result;
                #region Manipulating the Y Axis span
                double sum = 0;
                foreach (var fleetView in e.Result)
                {
                    sum = Math.Max(sum, fleetView.Series1 +
                                         fleetView.Series2 +
                                         fleetView.Series3 +
                                         fleetView.Series4 +
                                         fleetView.Series5);
                }
 
                ChartArea chartArea = radChart1.DefaultView.ChartArea;
                chartArea.AxisY.AutoRange = true;
                double min = chartArea.AxisY.ActualMinValue;
                double max = chartArea.AxisY.ActualMaxValue;
                double step = chartArea.AxisY.ActualStep;
                chartArea.AxisY.AutoRange = false;
                //chartArea.AxisY.MaxValue = sum; // This throws an exception
                chartArea.AxisY.AddRange(min, sum, step); // This gives me an unreadable scale
                #endregion
            }
        }
        public void SetChart(string strXValue, string y1, string y2, string y3, string y4, string y5)
        {
            radChart1.ItemsSource = null;
            radChart1.SeriesMappings.Clear();
            const int distance = 15;
            MapPresentationToStackedBarChart(strXValue, y1, distance, SERIES1);
            MapPresentationToStackedBarChart(strXValue, y2, distance, SERIES2);
            MapPresentationToStackedBarChart(strXValue, y3, distance, SERIES3);
            MapPresentationToStackedBarChart(strXValue, y4, distance, SERIES4);
            MapPresentationToStackedBarChart(strXValue, y5, distance, SERIES5);
        }
        private void MapPresentationToStackedBarChart(string strXValue, string yValue, int distance, string series)
        {
            if (!string.IsNullOrEmpty(yValue))
            {
                var mapping5 = new SeriesMapping();
                mapping5.ItemMappings.Add(new ItemMapping()
                                              {
                                                  AggregateFunction = ChartAggregateFunction.None,
                                                  DataPointMember = DataPointMember.XCategory,
                                                  FieldName = strXValue
                                              });
                mapping5.ItemMappings.Add(new ItemMapping(series, DataPointMember.YValue, ChartAggregateFunction.None));
                var sbsd5 = new StackedBarSeriesDefinition
                                {LabelSettings = {LabelDisplayMode = LabelDisplayMode.Outside, Distance = distance}};
                mapping5.SeriesDefinition = sbsd5;
                mapping5.LegendLabel = yValue;
                radChart1.SeriesMappings.Add(mapping5);
            }
        }
 This results in an even more messed up chart as seen in the attached "bar chart with modified y maximum.jpg".  What is the best way to ensure that large outlying stacked bar charts are not clipped?

Thanks.

5 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 20 Dec 2011, 01:49 PM
Hello Ralph,

If you are using auto range the Y axis will automatically adjust to ensure that all stacked bars are visible. I see that you are using manual range, so please check that the values set are high enough that no stacked bar will be clipped.

I have created a small demo application for you that demonstrates how you can create stacked bars in code behind.

Greetings,
Yavor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Ralph
Top achievements
Rank 1
answered on 20 Dec 2011, 02:55 PM
Actually I wrote that code, because auto range was not working. Before I manually adjusted the Y axis the bar graphs were clipped(see clipped-stacked-bar-chart.jpg). This is what the code looked like before

       void GetViewCompleted(object sender, GetViewCompletedEventArgs e)
        {
            txtUnAssignedMsg.Visibility = Visibility.Collapsed;
            SetChart("MyXThing", Y1, Y2, Y3, Y4, Y5);
            if (e.Result.Count > 0)
            {
                radChart1.ItemsSource = e.Result;
            }
        }


My code made the graphs look bad in a different way (see bar-chart-with-modified-y-maximum.jpg). I would prefer not to require the code I wrote. I think this a bug in the charting control. If you can tell me that the bug with the clipping has been fixed, I will be glad to go back to auto range. 

I'm not sure why auto range isn't working. I can tell you that my data can vary by orders of magnitude. One object may have series 1 through series 5 whose values add up into the millions, where another may have these values add only into the low thousands. 
0
Yavor
Telerik team
answered on 22 Dec 2011, 10:56 AM
Hello Ralph,

I checked in our bug tracking system and couldn't find any bug regarding stacked bars and auto range functionality. Can you please prepare for us a small runnable test project so that we can investigate it in our labs to determine what is going on. If your data comes from a web service you can replace that with a simple array for example to reduce the complexity of the application.

Regards,
Yavor
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Maxence
Top achievements
Rank 1
answered on 26 Dec 2011, 12:44 AM
Hi Yavor,

like i say in my other post (http://www.telerik.com/community/forums/silverlight/chart/problem-with-chartyeargroupdescriptor.aspx#1926516), i have the same behavior than Ralph.

thanks by advance for the efforts of support team.

Regards,

Maxence
0
Giuseppe
Telerik team
answered on 28 Dec 2011, 05:15 PM
Hello there,

We are still unable to reproduce the original issue that Ralph reported in this thread.

Please review the attached sample application that mimics the original screenshot data from clipped-stacked-bar-chart.jpg, uses automatic AxisY range and does not clip the stacked bar values and let us know if we are missing something out.


Regards,
Giuseppe
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Ralph
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Ralph
Top achievements
Rank 1
Maxence
Top achievements
Rank 1
Giuseppe
Telerik team
Share this question
or