Hi mukesh1,
You are not adding tooltip for each series. You are assigning tooltip for Chart1.Series["Tasks"]. So its shows in result last value on all row tooltip.
I have modified your code.
Using the above article i have created example. Check this example. Now please take its reference and correct your code.
HTML
<asp:Chart ID="Chart1" runat="server" Width="932px">
<Series>
<asp:Series Name="Tasks" YValuesPerPoint="6" ChartType="Column" CustomProperties="LabelStyle=Top"
YValueType="Int32" IsValueShownAsLabel="true">
<EmptyPointStyle IsValueShownAsLabel="false" IsVisibleInLegend="false" />
</asp:Series>
</Series>
<ChartAreas>
<asp:ChartArea Name="ChartArea1">
</asp:ChartArea>
</ChartAreas>
<Legends>
<asp:Legend Name="Task point" Alignment="Center" Docking="Right">
</asp:Legend>
</Legends>
</asp:Chart>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string query = string.Format("SELECT TOP 20 ShipCity, COUNT(OrderId) FROM Orders GROUP BY ShipCity");
DataTable dt = GetData(query);
DataSet ds = new DataSet();
ds.Tables.Add(dt);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string title = ds.Tables[0].Rows[i][0].ToString();
String totalpoint = (ds.Tables[0].Rows[i][1]).ToString();
if (totalpoint == "")
{
totalpoint = "0";
}
Series series = new Series();
series.XValueMember = dt.Columns[0].ColumnName;
series.YValueMembers = dt.Columns[1].ColumnName;
series.ChartType = SeriesChartType.Column;
series.YValuesPerPoint = 6;
series.YValueType = ChartValueType.Int32;
series.IsValueShownAsLabel = true;
series.LegendText = title;
Chart1.Series.Add(series);
Chart1.Series[i].Points.AddXY("Task" + (i + 1) + "" + "(" + ds.Tables[0].Rows[i][1].ToString() + ")", totalpoint);
Chart1.Series[i].ToolTip = title;
Chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.LineWidth = 0;
}
}
}
private static DataTable GetData(string query)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand(query);
String constr = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlDataAdapter sda = new SqlDataAdapter();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
return dt;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
Dim query As String = String.Format("SELECT TOP 20 ShipCity, COUNT(OrderId) FROM Orders GROUP BY ShipCity")
Dim dt As DataTable = GetData(query)
Dim ds As DataSet = New DataSet()
ds.Tables.Add(dt)
For i As Integer = 0 To ds.Tables(0).Rows.Count - 1
Dim title As String = ds.Tables(0).Rows(i)(0).ToString()
Dim totalpoint As String =(ds.Tables(0).Rows(i)(1)).ToString()
If totalpoint = "" Then
totalpoint = "0"
End If
Dim series As Series = New Series()
series.XValueMember = dt.Columns(0).ColumnName
series.YValueMembers = dt.Columns(1).ColumnName
series.ChartType = SeriesChartType.Column
series.YValuesPerPoint = 6
series.YValueType = ChartValueType.Int32
series.IsValueShownAsLabel = True
series.LegendText = title
Chart1.Series.Add(series)
Chart1.Series(i).Points.AddXY("Task" & (i + 1) & "" & "(" + ds.Tables(0).Rows(i)(1).ToString() & ")", totalpoint)
Chart1.Series(i).ToolTip = title
Chart1.ChartAreas("ChartArea1").AxisX.MajorGrid.LineWidth = 0
Next
End If
End Sub
Private Shared Function GetData(ByVal query As String) As DataTable
Dim dt As DataTable = New DataTable()
Dim cmd As SqlCommand = New SqlCommand(query)
Dim constr As String = ConfigurationManager.ConnectionStrings("ConString").ConnectionString
Dim con As SqlConnection = New SqlConnection(constr)
Dim sda As SqlDataAdapter = New SqlDataAdapter()
cmd.CommandType = CommandType.Text
cmd.Connection = con
sda.SelectCommand = cmd
sda.Fill(dt)
Return dt
End Function
Screenshots