Click here to Skip to main content
15,891,905 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have generated a chart dynamically, which sets its y-axis value automatically on the basis of its numbers (generate dynamically on the basis of data). Suppose its value comes in 4 diffrent numbers i.e.(12,8,17,15) then it sets y-axis range upto 22 no. but when data comes in (12,8,21,19) then it sets y-axis range upto 25 no, but I want to fix its range 25 in every case. I am using this code :
C#
string query = _query;
            SqlDataAdapter da = new SqlDataAdapter(query, con);
            DataTable dt = new DataTable();
            da.Fill(dt);
            string chart_name = System.DateTime.Now.Ticks + ".png";

            double[] yValues = { Convert.ToDouble(dt.Rows[0][1]), Convert.ToDouble(dt.Rows[1][1]), Convert.ToDouble(dt.Rows[2][1]), Convert.ToDouble(dt.Rows[3][1]) };
            string[] xValues = { dt.Rows[0][0].ToString(), dt.Rows[1][0].ToString(), dt.Rows[2][0].ToString(), dt.Rows[3][0].ToString() };

            double[] yValues2 = { Convert.ToDouble(dt.Rows[0][2]), Convert.ToDouble(dt.Rows[1][2]), Convert.ToDouble(dt.Rows[2][2]), Convert.ToDouble(dt.Rows[3][2]) };
            string[] xValues2 = { dt.Rows[0][0].ToString(), dt.Rows[1][0].ToString(), dt.Rows[2][0].ToString(), dt.Rows[3][0].ToString() };
            ChartArea chartArea = new ChartArea();
            Axis yAxis = new Axis(chartArea, AxisName.Y);
            Axis xAxis = new Axis(chartArea, AxisName.X);
            Chart1.Series["Current"].Points.DataBindXY(xValues, yValues);
            Chart1.Series["Preferred"].Points.DataBindXY(xValues2, yValues2);
            Chart1.Height = 250;
            Chart1.Width = 500;

            Chart1.AntiAliasing = AntiAliasingStyles.All;
            Chart1.TextAntiAliasingQuality = TextAntiAliasingQuality.High;
            using (var chartimage = new MemoryStream())
            {
                Chart1.SaveImage(Server.MapPath("~/images/" + chart_name), ChartImageFormat.Png);
                return chart_name;
            }
So if any body have an idea how can i fix Y-Axis data constantly (25), Kindly share with me.
Posted
Updated 2-Oct-12 22:41pm
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900