I want a 2D line chart for a list of points with x, y values.
I want 1 line, that goes threw the points, but I get 4 lines, 1 for each point.
I want the points to be in the right place, according to their numerical value. So that (1,1) point
Will be in 1 on x axis, 1 on y axis, and (7,9) point Will be in 7 on x axis, 9 on y axis.
I have this code.
List<Point> pointLs = new List<Point>(); pointLs.Add(new Point(1,1)); pointLs.Add(new Point(2, 4)); pointLs.Add(new Point(7, 9)); pointLs.Add(new Point(12, 20)); ultraChart1.DataSource = pointLs; this.ultraChart1.DataBind();
public class Point { public Point(double x, double y) { mX = x; mY = y; } private double mX; private double mY; public double Y { get { return mY; } set { mY = value; } } public double X { get { return mX; } set { mX = value; } } }
Sorry, I didn’t see that you want x and y numeric values (scatter chart).
Try this code:
private void Form1_Load(object sender, EventArgs e)
{
this.ultraChart1.ChartType = ChartType.ScatterChart;
this.ultraChart1.ScatterChart.ConnectWithLines = true;
this.ultraChart1.ScatterChart.LineAppearance.SplineTension = 0;
List<Point> pointLs = new List<Point>();
pointLs.Add(new Point("a", 1, 1));
pointLs.Add(new Point("b", 2, 4));
pointLs.Add(new Point("c", 7, 9));
pointLs.Add(new Point("d", 12, 20));
ultraChart1.DataSource = pointLs;
this.ultraChart1.DataBind();
}
public class Point
public Point(string label, double x, double y)
this.Label = label;
mX = x;
mY = y;
private string label;
private double mX;
private double mY;
public string Label
get { return label; }
set { label = value; }
public double X
get { return mX; }
set { mX = value; }
public double Y
get { return mY; }
set { mY = value; }
Great!
That's what I wanted.
Now, I want to scatterchart which contains 2 lines, for 2 lists.
for example I tried this, but it doesnt work.
List<Point> pointLs = new List<Point>(); pointLs.Add(new Point("a", 1, 1)); pointLs.Add(new Point("b", 2, 4)); pointLs.Add(new Point("c", 7, 9)); pointLs.Add(new Point("d", 12, 20)); List<Point> pointLs1 = new List<Point>(); pointLs1.Add(new Point("a", 2, 2)); pointLs1.Add(new Point("b", 4, 5)); pointLs1.Add(new Point("c", 9, 8)); pointLs1.Add(new Point("d", 12, 20)); List<List<Point>> data = new List<List<Point>>(); data.Add(pointLs); data.Add(pointLs1); ultraChart1.DataSource = data; this.ultraChart1.DataBind();
You can display the chart legend and you will see these labels. For the axis labels you can use chart titles. Try using this:
series1.Label = "Series 1";
series2.Label = "Series 2";
this.ultraChart1.Legend.Visible = true;
this.ultraChart1.Axis.X.Extent = 50;
this.ultraChart1.TitleBottom.Text = "Axis X";
this.ultraChart1.TitleBottom.HorizontalAlign = StringAlignment.Center;
this.ultraChart1.Axis.Y.Extent = 50;
this.ultraChart1.TitleLeft.Visible = true;
this.ultraChart1.TitleLeft.Text = "Axis Y";
this.ultraChart1.TitleLeft.HorizontalAlign = StringAlignment.Center;
How do I add label to the serieses so that it is possible for the user to diffrentiate the two serieses ?
I tried series1.Label = "Sereis 1" but it didnt work.
How do I add description to the axis so that it is possible to know that the horizontal axis is X, and vertical, is Y
You can add this with:
XYSeries series1 = new XYSeries();
series1.Points.Add(new XYDataPoint(1, 2, "label", false));
series1.Points.Add(new XYDataPoint(2, 3, "label", false));
series1.Points.Add(new XYDataPoint(7, 9, "label", false));
series1.Points.Add(new XYDataPoint(12, 20, "label", false));
XYSeries series2 = new XYSeries();
series2.Points.Add(new XYDataPoint(2, 2, "label", false));
series2.Points.Add(new XYDataPoint(4, 5, "label", false));
series2.Points.Add(new XYDataPoint(9, 8, "label", false));
series2.Points.Add(new XYDataPoint(12, 20, "label", false));
this.ultraChart1.Series.Add(series1);
this.ultraChart1.Series.Add(series2);