pixel3cs Posted May 13, 2008 Report Share Posted May 13, 2008 I use this code to initialize a Chart. If i don't add the chart as a control will compile and run ok, but if i try to put the chart as a control in my app this code will thrown an exception saying "Object not set to an instance of an object". What i am doing wrong? This is because my chart control is not initialized correct. Please help. if (clvi.LabelContent == "Histogram" && tablesListBox.SelectedIndex >= 0) { // get the selected table DataTable selectedDataTable = tablesListBox.Items[tablesListBox.SelectedIndex] as DataTable; // create the chart control ChartFX.WPF.Chart chart = new ChartFX.WPF.Chart(); chart.ItemsSource = null; chart.Series.Clear(); chart.AxesY.Clear(); chart.MultiPanes = true; // calculate the histogram data Histogram histogram = new Histogram(selectedDataTable, Properties.Settings.Default.HistogramBars); // add the histogram data to the chart //DataTemplate seriesTemplate = (DataTemplate)FindResource("NewBar2"); for (int seriesIndex = 0; seriesIndex < histogram.Charts.Length; seriesIndex++) { ChartFX.WPF.Axis axisY = new ChartFX.WPF.Axis(); chart.AxesY.Add(axisY); axisY.LabelFormat.Decimals = 2; ChartFX.WPF.SeriesAttributes series = new ChartFX.WPF.SeriesAttributes(); series.Template = new DataTemplate(); series.BindingPath = "Charts"; series.AxisY = axisY; chart.Series.Add(series); } chart.ItemsSource = histogram.Charts; // add the chart to the tab control ti.Content = chart;//if i comment this line the error will not be thrown } Quote Link to comment Share on other sites More sharing options...
JuanC Posted May 13, 2008 Report Share Posted May 13, 2008 It is hard to know without context about your data. - histogram.Charts should return a collection, this collection should have at least one numerical property - The name of such property should be used as the series.BindingPath - You might want to comment the series.Template = new DataTemplate() line as even if you can fix the NullReferenceException you will be generating an empty chart as the template you are providing has no visuals. I noticed you are using an old version of our control since the MultiPanes property is now AllSeries.MultiplePanes, please download the most recent build or send a message to wpf at softwarefx dot com for an updated version. Regards, JuanC Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.