Answered by:
Asp.net chart

Question
-
User-1706751376 posted
Hi, I have a bar chart. Its shows data with 3 bars .. I want to get the specific value which it display when i click over it.. for eg if my bar chart is showing 3 bars with value A,B and C. When I click on the bar with value C.. i want to capture this value in C# code.. any halp would be appriciated ..
right now i am able to capture its value like
protected void chart2_Click(object sender, ImageMapEventArgs e)
{
if (e.PostBackValue == "item")
{string fault = chart2.Series["Series1"].Points[0].AxisLabel;}}but since it is always getting value of first barchart (Point[0])... i am not sure how to get the value of the bar chart item where i clicked ..
please help .. please also let me know if there is any confusion .thanks
Wednesday, June 15, 2016 2:10 AM
Answers
-
User61956409 posted
Hi vishvishvish,
You could try to add PostBackValue to the chart series, the following sample is for your reference.
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Chart ID="Chart1" runat="server" OnClick="Chart1_Click"> <Series> <asp:Series Name="Series1"></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"></asp:ChartArea> </ChartAreas> </asp:Chart>
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add("FName"); dt.Columns.Add("FVal"); dt.Rows.Add("A", 180); dt.Rows.Add("B", 156); dt.Rows.Add("C", 203); Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar; Chart1.Series[0].XValueMember = "FName"; Chart1.Series[0].YValueMembers = "FVal"; Chart1.Series[0].PostBackValue = "#VALY"; Chart1.DataSource = dt; Chart1.DataBind(); } } protected void Chart1_Click(object sender, ImageMapEventArgs e) { string val = e.PostBackValue; Label1.Text = val; }
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 16, 2016 6:47 AM
All replies
-
User61956409 posted
Hi vishvishvish,
You could try to add PostBackValue to the chart series, the following sample is for your reference.
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> <asp:Chart ID="Chart1" runat="server" OnClick="Chart1_Click"> <Series> <asp:Series Name="Series1"></asp:Series> </Series> <ChartAreas> <asp:ChartArea Name="ChartArea1"></asp:ChartArea> </ChartAreas> </asp:Chart>
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DataTable dt = new DataTable(); dt.Columns.Add("FName"); dt.Columns.Add("FVal"); dt.Rows.Add("A", 180); dt.Rows.Add("B", 156); dt.Rows.Add("C", 203); Chart1.Series[0].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Bar; Chart1.Series[0].XValueMember = "FName"; Chart1.Series[0].YValueMembers = "FVal"; Chart1.Series[0].PostBackValue = "#VALY"; Chart1.DataSource = dt; Chart1.DataBind(); } } protected void Chart1_Click(object sender, ImageMapEventArgs e) { string val = e.PostBackValue; Label1.Text = val; }
Best Regards,
Fei Han
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, June 16, 2016 6:47 AM -
User-1706751376 posted
thanks . i will try and will let you know .. appreciate your reply .
Wednesday, June 29, 2016 4:38 PM