Wpf Chart Controls

how to create chart control in code behind wpf

You can not use "{Binding}" in Code.

You have to create a Binding using

new System.Windows.Data.Binding(...)

see: https://learn.microsoft.com/en-us/dotnet/api/system.windows.data.binding.-ctor?view=netframework-4.7.2

Update:
And to answer your second question: < chart:ClusteredColumnChart.Series > is an attribute not an object.

Update 2:
Binding example:

var b = new System.Windows.Data.Binding {Source = dt};
series.SetBinding(ChartSeries.ItemsSourceProperty, b);

Or if you want to set the ItemsSource directly just use this without any Bindings:

series.ItemsSource = dt;

how to add .net chart component in wpf

The hint is in the namespace name: Systems.Windows.Forms.DataVisualization.Charting.Chart, it's a System.Windows.Forms component: WinForms. WPF is completely different (though its placement immediately in System.Windows (System.Windows.Controls) will lead to some confusion.

You can still use it, but you need to use System.Windows.Forms.Integration.WindowsFormsHost to host a WinForms component in a WPF XAML document, see here: https://msdn.microsoft.com/en-us/library/vstudio/ms751761(v=vs.100).aspx

Alternatively it's probably best to stick to WPF and use a WPF-based charting control, there is sage advice here: WPF chart controls

WPF chart control exists by default or I have to do an external download?

I think this is what you are looking for : http://www.nuget.org/packages/WPFToolkit.DataVisualization/

<Window x:Class="drawtextonbitmap.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:chartingToolkit="clr-namespace:System.Windows.Controls.DataVisualization.Charting;assembly=System.Windows.Controls.DataVisualization.Toolkit"
Title="MainWindow" Height="350" Width="525">
<Grid>
<chartingToolkit:Chart />
</Grid>
</Window>

If you want it to appear in the ToolBox :

  • right click ToolBox -> Choose Items
  • click Browse
  • go to your project folder
  • open \packages\WPFToolkit.DataVisualization.3.5.50211.1\lib\System.Windows.Controls.DataVisualization.Toolkit.dll
  • press Ok
  • it will be on 'Common WPF controls' section

Make sure to install mentioned package before using the Package Manager Console : http://docs.nuget.org/docs/start-here/using-the-package-manager-console

PM> Install-Package WPFToolkit.DataVisualization

How to host a winform chart control into a WPF view?

The issue is not at the WPF/WinForms interop layer but in the WinForms.

You must add a ChartArea:

miGraficoWF.ChartAreas.Add("Default");

WPF chart controls in MVVM

Is this the best one when we think in terms of OpenSource and MVVM binding ?

I'm not a big fan of WPF Toolkit controls.

I've written and tested apps that used them in the past, and they were flaky, and weren't very well designed.

In particular, the DataGrid was flaky. It was often the cause of exceptions and accessibility problems.

The AutoCompleteBox wasn't well designed. It tries to be extensible, but doesn't do a very good job of it. It didn't work very cleanly for use as a directory auto-complete box (due to issues with updating the auto-complete data source).

They also haven't been updated in nearly two years, yet have numerous reported bugs, which says to me that they've been abandoned. The Chart control you ask about is in of "preview" quality, not "stable", which is worse still.

Here are some places you could look for alternatives:

  • Are there good WPF control libraries out there? - I think all the ones linked are commercial
  • http://wpftutorial.net/3rdPartyLibs.html - some off this link aren't commercial, and this is a much bigger list

The second link refers to a "Free 3D chart" on CodeProject. Can't recommend for or against it, I just wanted to point it out.



Related Topics



Leave a reply



Submit