Please refer below code populated from database.
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string constring = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constring))
{
using (SqlCommand cmd = new SqlCommand("SELECT ActionId,StartTime,Task FROM Customers", con))
{
cmd.CommandType = CommandType.Text;
using (SqlDataAdapter sda = new SqlDataAdapter(cmd))
{
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
DateTime[] x = new DateTime[dt.Rows.Count];
string[] y = new string[dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++)
{
DateTime dTime = DateTime.ParseExact(dt.Rows[i]["StartTime"].ToString(), "h:mm tt",
CultureInfo.InvariantCulture, DateTimeStyles.None);
x[i] = dTime;
y[i] = dt.Rows[i]["Task"].ToString();
}
Chart1.Series[0].Points.DataBindXY(y, x);
Chart1.ChartAreas[0].AxisY.LabelStyle.Format = "hh:mm tt";
Chart1.Series[0].ChartType = SeriesChartType.Line;
Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = false;
Chart1.Legends[0].Enabled = true;
}
}
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim constring As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As SqlConnection = New SqlConnection(constring)
Using cmd As SqlCommand = New SqlCommand("SELECT ActionId,StartTime,Task FROM Customers", con)
cmd.CommandType = CommandType.Text
Using sda As SqlDataAdapter = New SqlDataAdapter(cmd)
Using dt As DataTable = New DataTable()
sda.Fill(dt)
Dim x As DateTime() = New DateTime(dt.Rows.Count - 1) {}
Dim y As String() = New String(dt.Rows.Count - 1) {}
For i As Integer = 0 To dt.Rows.Count - 1
Dim dTime As DateTime = DateTime.ParseExact(dt.Rows(i)("StartTime").ToString(), "h:mm tt", CultureInfo.InvariantCulture, DateTimeStyles.None)
x(i) = dTime
y(i) = dt.Rows(i)("Task").ToString()
Next
Chart1.Series(0).Points.DataBindXY(y, x)
Chart1.ChartAreas(0).AxisY.LabelStyle.Format = "hh:mm tt"
Chart1.Series(0).ChartType = SeriesChartType.Line
Chart1.ChartAreas("ChartArea1").Area3DStyle.Enable3D = False
Chart1.Legends(0).Enabled = True
End Using
End Using
End Using
End Using
End Sub