C#:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LineGraphFunction();
}
}
//code for line graph
protected void LineGraphFunction()
{
string id = Request.QueryString["Id"].ToString();
string query = string.Format("SELECT x,y from Table1 where ID = '" + id + "' and DeletionDate is null");
DataTable dt = GetData(query);
string[] x = new string[dt.Rows.Count];
decimal[] y = new decimal[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToDecimal(dt.Rows[i][1]);
}
LineChart1.Series.Add(new AjaxControlToolkit.LineChartSeries { Data = y });
LineChart1.CategoriesAxis = string.Join(",", x);
//LineChart1.ChartTitle = "Goal Function Graph";
if (x.Length > 3)
{
LineChart1.ChartWidth = (x.Length * 75).ToString();
}
LineChart1.Visible = true;
}
//for line graph
private static DataTable GetData(string query)
{
DataTable dt = new DataTable();
string constr = ConfigurationManager.ConnectionStrings["sgwebdbConnectionString"].ConnectionString;
using (MySqlConnection con = new MySqlConnection(constr))
{
using (MySqlCommand cmd = new MySqlCommand(query))
{
using (MySqlDataAdapter sda = new MySqlDataAdapter())
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
}
}
return dt;
}
}
HTML:
<cc1:LineChart ID="LineChart1" Width="500px" runat="server" ChartHeight="300" ChartWidth = "450" TooltipBorderColor="#D8D8D8" TooltipFontColor="blue"
ChartType="Basic" ChartTitleColor="#0E426C" Visible = "false" BorderColor="Blue" BorderWidth="1px"
CategoryAxisLineColor="#D08AD9" ValueAxisLineColor="#D08AD9" BaseLineColor="#A156AB">
</cc1:LineChart>
Problem is:
In the "LineChart", everytime last "y-axis" point is going out of graph (i.e., somewhere in the footer of x-axis)
X-axis
|
Y-axis
|
3.4
|
5.2
|
5.3
|
7
|
2
|
8.7
|
1) like in above table, all the point will plot except the last x-axis and y-axis points. Also, y-axis value = 8.7 goes away from graph and comes in the footer of x-axis line.
2) like if x-axis = 3, y-axis=6, then 6 goes out of the graph and comes in footer of x-axis line.
But this problem occurs only when Im using SELECT query for a "particular Id" i.e.,
SELECT x,y from Table1 where Id='Gaug9' and DeletionDate is null
If I will remove where Id=' ' then it will work fine.
But I need to plot graph based on particular Id's.
Please reply how to solve this problem.