I am using asp chart in my webpage. Data inside Chart is coming from Database Table.
Sample DB Table:
Id
|
X-axis
|
Y-axis
|
1
|
1.2
|
0.4
|
2
|
2
|
-1
|
3
|
-2.4
|
0.2
|
4
|
10.8
|
-0.3
|
5
|
5.6
|
1
|
C# code:
protected void Page_Load(object sender, EventArgs e)
{
NodeChart();
}
protected void NodeChart()
{
Chart1.Visible = true;
string id = Request.QueryString["Id"].ToString();
string query = string.Format("SELECT x,y from Table where ID= '" + id + "' and DeletionDate is null");
DataTable dt = GetData(query);
string[] x = new string[dt.Rows.Count];
double[] y = new double[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
x[i] = dt.Rows[i][0].ToString();
y[i] = Convert.ToDouble(dt.Rows[i][1]);
}
Chart1.Series[0].Points.DataBindXY(x, y);
Chart1.Series[0].ChartType = SeriesChartType.Line;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.Legends[0].Enabled = true;
Color col = ColorTranslator.FromHtml("#cc99cc");
Chart1.ChartAreas["ChartArea1"].AxisX.LineColor = col;
Chart1.ChartAreas["ChartArea1"].AxisX.LineWidth = 2;
Chart1.ChartAreas["ChartArea1"].AxisY.LineColor = col;
Chart1.ChartAreas["ChartArea1"].AxisY.LineWidth = 2;
//to fix the Max and Min value of Y-axis
Chart1.ChartAreas["ChartArea1"].AxisY.Minimum = -1;
Chart1.ChartAreas["ChartArea1"].AxisY.Maximum = 1;
}
private static DataTable GetData(string query)
{
var temp = PSI.DataAccess.Database.DatabaseManager.GetConnection().GetDataAdapter(query, null);
DataTable dt = new DataTable();
temp.Fill(dt);
return dt;
}
HTML code:
<asp:Chart ID="Chart1" runat="server" Height="300px" Width="400px" Visible="false" BorderlineColor="#e5e4e2" BorderlineWidth="2" BorderlineDashStyle="Solid">
<Titles>
<asp:Title ShadowOffset="3" Name="Items"/>
</Titles>
<Legends>
<asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False" Name="Default" LegendStyle="Row" />
</Legends>
<Series>
<asp:Series Name="Line" ChartType="Line" BorderWidth="1" MarkerStyle="Circle" MarkerBorderWidth="3" MarkerBorderColor="Blue" Color="DarkBlue"/>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1"/>
</ChartAreas>
</asp:Chart>
I am facing 3 issues in it:
1) If DB table has x-axis value= 10.8 for Id="4", and x-axis value= 5.6 for Id="5" (ab above DB sample table)
i.e.,When I enter the value of the node X lesser than the previous node X
then graph is wrongly plotted, i.e, x-axis=10.8 is plotted first in graph and then x-axis=5.6 which is wrong.
2) If DB table has x-axis value in negative i.e., -2.4 then that value is also plotted in (+ +) quadrant which is wrong.
3) I want to fix line at the 0 level for this graph.
I hope I made myself clear
Please help me to solve above 3 issues.
Please reply