So I'm trying to create a chart in my .NET 6 WinForm application, and I can't find the charts option in my toolbox. Does anyone know why it is doing it? Did they remove charts in .NET 6? And if so, how can I create a chart? Thanks
-
MSChart should be in the Data section.TaW– TaW2022-05-15 18:53:33 +00:00Commented May 15, 2022 at 18:53
-
1Well, it isn't thereSomeone with many names– Someone with many names2022-05-15 18:54:35 +00:00Commented May 15, 2022 at 18:54
-
Then your installation is not correct or maybe you are not really creating a WinForms project.TaW– TaW2022-05-15 18:56:50 +00:00Commented May 15, 2022 at 18:56
-
2Have you read developercommunity.visualstudio.com/t/… - it gives some pointers about what to install ..Caius Jard– Caius Jard2022-05-15 18:56:51 +00:00Commented May 15, 2022 at 18:56
-
stuartd. I see... If so, are there any alternatives for the Microsoft library of charts?Someone with many names– Someone with many names2022-05-15 18:57:52 +00:00Commented May 15, 2022 at 18:57
|
Show 1 more comment
2 Answers
So, I found a work-around. It's not the most elegant, nor particularly performant, but since I just wanted a quick visualisation tool for internal testing, this did the trick nicely. Here's what I ended up with (basic scatter plot, but the principle can be adapted for line charts and box charts etc):
Process
- Add a picture box to your form
- populate it with an empty bitmap to the scale that you want to display
- for each data point you want to plot, draw a circle on the bitmap at those coordinates using Graphics.DrawEllipse
Example Code
private void PlotCoordinates(List<Coordinates> coordinateList, Pen pen)
{
List<Rectangle> boundingBoxes = GenerateBoundingBoxes(coordinateList);
using (Graphics g = Graphics.FromImage(image))
{
foreach (Rectangle boundingBox in boundingBoxes)
{
g.DrawEllipse(pen, boundingBox);
}
}
}
private List<Rectangle> GenerateBoundingBoxes(List<Coordinates> coordinateList)
{
var boundingBoxes = new List<Rectangle>(coordinateList.Count);
//dataPointDiameterPixels is the diameter you want your ellipse to be on the plot
//it needs to be an odd to be accurate
int dataPointCetralisingOffset = dataPointDiameterPixels / 2;
int rectLength = dataPointDiameterPixels;
foreach (Coordinates coordinates in coordinateList)
{
int topLeftX = Maths.Max(coordinates.X - dataPointCetralisingOffset, 0);
int topLeftY = Maths.Max(coordinates.Y - dataPointCetralisingOffset, 0);
var box = new Rectangle(topLeftX, topLeftY, rectLength, rectLength);
boundingBoxes.Add(box);
}
return boundingBoxes;
}
Comments
WinForms has been depreciated and a lot of its functionality hasn't made it into .NET 6. There are no plans to change this. If you find an alternative solution please share it.
See this for more info: https://github.com/dotnet/winforms/discussions/6163
2 Comments
Simone
Winforms charts has been deprecated.
SpicyCatGames
Winforms has not been deprecated. It might have been depreciated though.
