Support for .NET Framework graphs have been moved to .NET Core, but how to keep drawing the image?

Viewed 4859

System.Windows.Forms has been moved to .NET Core and is now available in the form of a NuGet package.
It seems Microsoft has specifically listed the components that haven't been moved over:
https://docs.microsoft.com/en-us/dotnet/core/compatibility/winforms#removed-controls

I need to migrate use of the charting functionality in:
using System.Windows.Forms.DataVisualization.Charting;
When I use the drawing functionality of the base control class I get the following error:
The type 'Control' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Windows.Forms, Version=4.0.0.0

When I go to the definition of the Charts class it shows:

public class Chart :Forms.Control 

With the keywords before the colon recognized, but not after.
So somehow the Forms.Control isn't available, yet the code compiles...

The following features where taken from the base Control class and are now no longer avialable:
- BeginInit; Start putting in graph components
- EndInit; Done putting in graph components
- Update; Visually show the graph on screen
- SaveImage; Write graph visuals to a memory stream

How can these features be implemented in .NET CORE?

Since System.Windows.Forms has been migrated to .NET Core I added a using to it to my code, this doesn't help.
I installed the NuGet package for Microsoft.Windows.Compatibility, this didn't help either.

Edit:
I've installed the following NuGet packages:

System.Windows.Forms.DataVisualization 1.0.0-prerelease.20110.1
System.Drawing.Common 4.7.0
Microsoft.Windows.Compatibility 3.1.0

I've tried to install the latest preview version but this tries to upgrade all kinds of dependencies to 5.0.0-preview.1.20120.5, which cannot be found.
The following properties have been added the following properties to my .csproj

<UseWpf>true</UseWpf>
<UseWindowsForms>true</UseWindowsForms>
2 Answers

Despite being retired there is still a nuget package available (For .NET 5): HIC.System.Windows.Forms.DataVisualization

How can these features be implemented in .NET CORE?

Programming. A LOT of programming. That said...

...given the posts at https://github.com/dotnet/winforms/issues/112 I would assume the error is on your end. The reference indicates that this has been fixed in April 2019 with .NTE core 3.0 preview 5 where this is mentioned as being ports.

As of today, https://www.nuget.org/packages/System.windows.forms.datavisualization lists DataVisualization as in preview. As of a month ago inidicates that it DID get a number of updates because that nuget package is a month old - but you need to:

  • Import it explicitly
  • Allow previews to be imported.

The github reference for this is at https://github.com/dotnet/winforms-datavisualization

Note that the readme on github states:

"This repo is read-only. We consider the System.Windows.Forms.DataVisualization deprecated and we only provide it to ease porting to .NET Core 3. We're not going to innovate in this component and subsequently will not accept any PRs."

This sort of contradicts the preview character (at least they should release it).

Not using it myself. This is basically what I could find with a minute of searching in google, starting with the namespace and "core" as keywords.

Long term you may consider moving to a commercial charting compoinent. I have great experience with SciChart, but that is a really high end high performance component. Pretty much every component library has one.

Related