HI Dharmendr;
Sir you helped me alot i really thankful to you.
Sir i have to update my graph according to my database:
my database table record is like that:
all the datatype value of column is nvarchar(50)
ipaddress time average pingtime
192.168.15.167 1:15 25 25-5-2021 1:15AM
192.168.15.167 2:30 50 25-5-2021 2:30AM
192.168.15.167 4:20 70 25-5-2021 4:20AM
192.168.15.167 7:30 100 25-5-2021 7:30AM
192.168.15.167 8:30 50 25-5-2021 8:30PM
192.168.15.167 9:20 70 25-5-2021 9:20PM
192.168.15.167 11:50 100 25-5-2021 11:50PM
192.168.15.167 1:00 25 26-5-2021 1:00AM
192.168.15.167 1:16 50 26-5-2021 1:16AM
192.168.15.167 2:20 75 26-5-2021 2:20AM
192.168.15.167 10:16 100 26-5-2021 10:16AM
and so on.
like it saving the record contineously according to date and time.
The problem occuring on my code is that line on graph doesnot move next date record. it doesnot move on to new time when it is changing date it move back to previous time.
And secondly i want to use pingtime column on my xaxis as time only and wants when the date change according to that date record should shown on graph till one weeks. after one week new time and date starts on graph and so on.
i have to shown one weeks record on my graph according to date and time.
Can you help me by updating my code.
my code is here.
JAVASCRIPT:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", { packages: ["corechart"] });
google.setOnLoadCallback(drawChart);
function drawChart() {
var options = {
title: 'ipaddress',
width: 600,
height: 400,
bar: { groupWidth: "95%" },
legend: { position: "none" },
isStacked: true
};
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetChartData",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var data = new google.visualization.DataTable();
data.addColumn('date', 'pingtime');
data.addColumn('number', 'average');
for (var i = 0; i < r.d.length; i++) {
data.addRow([new Date(parseInt(r.d[i][0].substr(6))), parseInt(r.d[i][1])]);
}
var chart = new google.visualization.LineChart($("#chart")[0]);
chart.draw(data, options);
},
failure: function (r) {
alert(r.responsetext);
},
error: function (r) {
alert(r.responsetext);
}
});
}
</script>
<div id="chart" style="width: 900px; height: 500px;">
</div>
C#:
namespace WebApplication13
{
public partial class WebForm1 : System.Web.UI.Page
{
[WebMethod]
public static List<object> GetChartData()
{
string query = "SELECT [pingtime],[average] FROM [dbo].[graph] WHERE ipaddress='192.168.15.167'";
string constr = ConfigurationManager.ConnectionStrings["dbcs"].ConnectionString;
List<object> chartData = new List<object>();
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
chartData.Add(new object[]
{
Convert.ToDateTime(sdr["pingtime"]), sdr["average"]
});
}
}
con.Close();
return chartData;
}
}
}
}
}