Exception while adding bar,column,area series thru C# code

Jan 16, 2013 at 6:03 AM
Edited Jan 16, 2013 at 6:04 AM

Hi , I was trying to add series dynamically to a chart rather adding them thru XAML. I am successful in adding pie & line chart but experiencing a exception while adding bar , column , area charts . I am unable to track the cause.

My Code :

        private Binding GetBindingForElementName(String name)
        {
            Binding binding = new Binding();
            binding.Path = new PropertyPath(name);
            return binding;
        }

  public void AddSeriesForChartTypeWithData(ChartType chartType,String _seriesTitle,IList<ImChartSeriesData> chartseriesData)
        {
            

            switch(chartType)
            {

                case ChartType.PieChart:
                    {
                        PieSeries pieSeries = new PieSeries();
                        pieSeries.Title = "Pie Chart";
                        pieSeries.IndependentValueBinding = this.GetBindingForElementName("xaxisValue");
                        pieSeries.DependentValueBinding = this.GetBindingForElementName("yaxisValue");
                        pieSeries.ItemsSource = chartseriesData;
                        pieSeries.IsSelectionEnabled = true;
                        pieSeries.SelectionChanged += pieSeries_SelectionChanged;
                        Chart.Series.Add(pieSeries);

                    }
                    break;
                case ChartType.ColumnChart:
                    {
                        ColumnSeries columnSeries = new ColumnSeries();
                        columnSeries.Title = "Colum Chart";
                        columnSeries.ItemsSource = chartseriesData;
                        columnSeries.IndependentValueBinding = this.GetBindingForElementName("xaxisValue");
                        columnSeries.DependentValueBinding = this.GetBindingForElementName("yaxisValue");
                        columnSeries.Loaded +=columnSeries_Loaded;
                        columnSeries.IsSelectionEnabled = true;
                        Chart.Series.Add(columnSeries);

                    }
                    break;

                case ChartType.BarChart:
                    {
                        BarSeries barSeries = new BarSeries();
                        barSeries.Title = "BarSeries Chart";
                        barSeries.IndependentValueBinding = this.GetBindingForElementName("xaxisValue");
                        barSeries.DependentValueBinding = this.GetBindingForElementName("yaxisValue");
                        barSeries.ItemsSource = chartseriesData;
                        barSeries.IsSelectionEnabled = true;
                        Chart.Series.Add(barSeries);

                        Chart.InvalidateArrange();
                        Chart.InvalidateMeasure();

                    }
                    break;

                case ChartType.BubbleChart:
                    {
                        BubbleSeries bubbleSeries = new BubbleSeries();
                        bubbleSeries.Title = "Bubble Chart";
                        bubbleSeries.IndependentValueBinding = this.GetBindingForElementName("xaxisValue");
                        bubbleSeries.DependentValueBinding = this.GetBindingForElementName("yaxisValue");
                        bubbleSeries.ItemsSource = chartseriesData;
                        bubbleSeries.IsSelectionEnabled = true;
                        Chart.Series.Add(bubbleSeries);

                    }
                    break;

                case ChartType.LineChart:
                    {
                        LineSeries lineSeries = new LineSeries();
                        lineSeries.Title = "Line Chart";
                        lineSeries.IndependentValueBinding = this.GetBindingForElementName("xaxisValue");
                        lineSeries.DependentValueBinding = this.GetBindingForElementName("yaxisValue");
                        lineSeries.ItemsSource = chartseriesData;
                        lineSeries.IsSelectionEnabled = true;
                        Chart.Series.Add(lineSeries);

                    }
                    break;
                
               
            }
        } 
Exception file: EdgePanel.CS
   foreach (UIElement element in Children.OfType<UIElement>().Where(child => GetEdge(child) == Edge.Center))
            {
                //try
                //{
                    element.Measure(centerSize);
                //}
                //catch (Exception exception)
                //{
                //    System.Diagnostics.Debug.WriteLine(exception.Message);
                //}
            }
Try , Catch doesnt help for me . I am not sure i am missing anything
Exception :
An exception of type 'System.Exception' occurred in WinRTXamlToolkit.Controls.DataVisualization.DLL but was not handled in user code
Additional information: Exception from HRESULT: 0x880008AF
If there is a handler for this exception, the program may be safely continued.
Coordinator
Jan 17, 2013 at 5:47 AM
Edited Jan 17, 2013 at 5:50 AM

Can you provide more exception details? Try enabling mixed debugging (in project properties) and Microsoft public symbols (options/debugging).

Also, someone mentioned the charts don't work if the control is too small - the exception in Measure code might be a clue to the same problem.

Otherwise - please share a sample repro project to help debug the issue.

Jan 17, 2013 at 7:38 AM
Edited Jan 17, 2013 at 9:01 AM

Even after enabling the options which u have mentioned i am unable to get more details on that .

I have tried placing the chart control in various sizes that didnt work out.

pie , area , line is working fine . issues in other chart types.

You may checkout my sample project thru SVN checkout from google code
 http://libraryworkaround.googlecode.com/svn/trunk/ libraryworkaround-read-only


Jan 25, 2013 at 9:22 AM

Hi , Any issues on check out . I am still facing the exception.

Coordinator
Jan 25, 2013 at 10:00 AM

Sorry, I don't know what's wrong.

Jan 25, 2013 at 11:37 AM
Edited Jan 25, 2013 at 11:39 AM

Hi , Do you mean you were not able to run the code or track the issue ?

No problem , are you planning to support spreadsheet read/write operation ? 

(say, I need to import a spreadsheet ,read &  manipulate the data)

If not , Can you suggest me any other opensource libraries which could do the required stuff.

Coordinator
Jan 25, 2013 at 4:24 PM

I ran the code and saw the problem, but couldn't quickly figure out what was wrong - it would require more work and I don't have the time right now, sorry.

I think there might be some spreadsheet controls out there from Syncfusion and ComponentOne. I seriously doubt there is anything open source.

Jan 27, 2013 at 10:15 AM

Many thanks for your response . Let me know if you could figure the issue when you get some time..

Wishes for great job & contribution .. !!!!

Feb 18, 2013 at 2:08 PM
My Problem like rajmohank.
     When i using ColumnSeries  class , the program will throw System.Exception at "element.Measure(centerSize);" statement,
but using SeriesSeries , fine.
     someone has advice?
Jul 19, 2013 at 9:53 AM
Not sure if this helps, but i had the same problem i fixed it by adding a chart with the series of the type i wanted to dynamically create and setting its visibility to collapsed this seems to fix my problem.

my guess is it needed to load stuff that it dosnt if you only create dynamic charts.
Jul 19, 2013 at 1:23 PM
@Crash23873 Exactly . Thanks for sharing . Me too used the same hack .