Jump to content
Software FX Community

What i am doing wrong?


pixel3cs
 Share

Recommended Posts

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
  }

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...