Example: Scatter Chart
A scatter plot is constructed in this example. Three data sets are used and a legend is added to the chart.
using Imsl.Chart2D;
using System;
using System.Windows.Forms;
public class ScatterEx1 : FrameChart
{
public ScatterEx1()
{
Chart chart = this.Chart;
AxisXY axis = new AxisXY(chart);
int npoints = 20;
double dx = .5 * System.Math.PI / (npoints - 1);
double[] x = new double[npoints];
double[] y1 = new double[npoints];
double[] y2 = new double[npoints];
double[] y3 = new double[npoints];
// Generate some data
for (int i = 0; i < npoints; i++)
{
x[i] = i * dx;
y1[i] = System.Math.Sin(x[i]);
y2[i] = System.Math.Cos(x[i]);
y3[i] = System.Math.Atan(x[i]);
}
Data d1 = new Data(axis, x, y1);
Data d2 = new Data(axis, x, y2);
Data d3 = new Data(axis, x, y3);
// Set Data Type to Marker
d1.DataType = Imsl.Chart2D.Data.DATA_TYPE_MARKER;
d2.DataType = Imsl.Chart2D.Data.DATA_TYPE_MARKER;
d3.DataType = Imsl.Chart2D.Data.DATA_TYPE_MARKER;
// Set Marker Types
d1.MarkerType = Data.MARKER_TYPE_CIRCLE_PLUS;
d2.MarkerType = Data.MARKER_TYPE_HOLLOW_SQUARE;
d3.MarkerType = Data.MARKER_TYPE_ASTERISK;
// Set Marker Colors
d1.MarkerColor = System.Drawing.Color.Red;
d2.MarkerColor = System.Drawing.Color.Black;
d3.MarkerColor = System.Drawing.Color.Blue;
// Set Data Labels
d1.SetTitle("Sine");
d2.SetTitle("Cosine");
d3.SetTitle("ArcTangent");
// Add a Legend
Legend legend = chart.Legend;
legend.SetTitle(new Text("Legend"));
legend.IsVisible = true;
// Set the Chart Title
chart.ChartTitle.SetTitle("Scatter Plot");
}
public static void Main(string[] argv)
{
System.Windows.Forms.Application.Run(new ScatterEx1());
}
}
Output
Link to C# source.