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 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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With