I am trying to build basic histogram that is located in examples of ScottPlot text. I can not manage how to join this code to my project Windows Forms App and make it work:
ScottPlot.Version.ShouldBe(4, 1, 70);
var plt = new ScottPlot.Plot(600, 400);
// create a histogram with a fixed number of bins
ScottPlot.Statistics.Histogram hist = new(min: 140, max: 220, binCount: 100);
// add random data to the histogram
Random rand = new(0);
double[] heights = ScottPlot.DataGen.RandomNormal(rand, pointCount: 1234, mean: 178.4, stdDev: 7.6);
hist.AddRange(heights);
// show the histogram counts as a bar plot
plt.AddBar(values: hist.Counts, positions: hist.Bins);
// customize the plot style
plt.YAxis.Label("Count (#)");
plt.XAxis.Label("Height (cm)");
plt.SetAxisLimits(yMin: 0);
plt.SaveFig("stats_histogram.png");
Could somebody explain how to use basic example with real Plot control? And here is my current code that i have now:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void formsPlot1_Load(object sender, EventArgs e)
{
CreateChart();
}
void CreateChart()
{
ScottPlot.Statistics.Histogram hist = new(min: 140, max: 220, binCount: 100);
double[] dataX = new double[] { 1, 2, 3, 4, 5 };
double[] dataY = new double[] { 1, 4, 9, 16, 25 };
formsPlot1.Plot.AddScatter(dataX, dataY);
formsPlot1.Refresh();
}
}
The code to make ScottPlot alive is very simple: