none
条形图问题 RRS feed

  • 问题

  • 大家好,
    我有一个条形图表,它显示了3栏ABC,我希望可以得到我点击的那个条形的值显示在下面。或者可以显示这个值得详细信息,请问如何实现。谢谢
    2016年10月27日 1:26

全部回复

  • 你好,

    因为我们不清楚你使用的是什么图表,我建议你可以使用ASP.NET mschart控件,这个控件有一个onclick事件,在这个时间中,我们可以获取到你到你点击的栏目的Y 的值。

    你只需要给你Series设置指定的PostBackValue的值。

    代码如下:

    <asp:Series Name="Series1" PostBackValue="#VAL"></asp:Series>

    这个值可以有很多种选择,列表如下:

    https://msdn.microsoft.com/zh-cn/library/dd456687.aspx

    详细示例代码:

     <div>
            <asp:Chart ID="Chart1" OnClick="Chart1_Click1" runat="server" Width="836px" >
                <Series>
                    <asp:Series Name="Series1" PostBackValue="#VAL"></asp:Series>
                </Series>
                <ChartAreas>
                    <asp:ChartArea Name="ChartArea1"></asp:ChartArea>
                </ChartAreas>
            </asp:Chart>
            Result:<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        </div>

    后台代码:

     protected void Page_Load(object sender, EventArgs e)
            {
                DataSet ds = new DataSet();
    
                DataTable dt = new DataTable();
                dt.Columns.Add("weightNow", typeof(Int32));
                dt.Columns.Add("dateNow", typeof(DateTime));
                DateTime departure = new DateTime(2016, 5, 12);
                DateTime arrival = new DateTime(2016, 6, 13);
                DateTime arrival2 = new DateTime(2016, 7, 14);
                DateTime departure1 = new DateTime(2016, 4, 12);
                DateTime arriva1l = new DateTime(2016, 3, 13);
                DateTime arrival22 = new DateTime(2016, 2, 14);
                dt.Rows.Add(30, departure);
                dt.Rows.Add(42, arrival);
                dt.Rows.Add(54, arrival2);
                dt.Rows.Add(74, departure1);
                dt.Rows.Add(24, arriva1l);
                dt.Rows.Add(64, arrival22);
                ds.Tables.Add(dt);
                //Chart1.Series["Series1"].ChartType = SeriesChartType.Spline;
                Chart1.Series["Series1"]["DrawingStyle"] = "Emboss";
                Chart1.DataSource = ds.Tables[0];
                
                Chart1.Series["Series1"].YValueMembers = "weightNow";
                Chart1.Series["Series1"].XValueMember = "dateNow";
                Chart1.Series["Series1"].XValueType = ChartValueType.DateTime;
                //Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "yyyy-MM-dd";
                //Chart1.ChartAreas["ChartArea1"].AxisX.IntervalType = DateTimeIntervalType.Months;
                DateTime minDate = new DateTime(2016, 3, 13).AddSeconds(-1);
                DateTime maxDate = new DateTime(2016, 6, 13); // or DateTime.Now;
                Chart1.ChartAreas["ChartArea1"].AxisX.Minimum = minDate.ToOADate();
                Chart1.ChartAreas["ChartArea1"].AxisX.Maximum = maxDate.ToOADate();
                Chart1.DataBind();
            }
    
            protected void Chart1_Click1(object sender, ImageMapEventArgs e)
            {
                Label1.Text = e.PostBackValue;
            }



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    2016年10月28日 10:21
  • 你好 Anne_Wx,

    这个问题解决了吗?现在有什么进展? 如果没有解决,请告诉我们你的问题,微软ASP.NET 专家会帮助解决。

    Best regards,

    yanjin 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2016年11月11日 9:50