Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3550
How to make line chart?
posted

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; }
        }
       
    }    


Parents
  • 17605
    posted

    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; }

                }

            }

Reply Children