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
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
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
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):
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;
}
Kirsan created a fork that works with .NET 6