locked
how to bind data column to series label? RRS feed

  • Question

  • Hey,
     im working on a bar chart at runtime that has these data source :

    ClientName             Percentage                      Sessions                               URL

    xxxxx                             33                                  1/3                    "~/Users/xxxxx.aspx
    yyyyy                             66                                  2/3                    "~/Users/yyyyy.aspx
    hhhhh                            100                                3/3                    "~/Users/hhhhh.aspx

    and i have these :
    Chart1.Series[0].XValueMember = "ClientName";
    Chart1.Series[0].YValueMembers =
    "Percentage";

    now i need to set the series label to the "Sessions" column or in other words i need to bind "Sessions" column to label of series and to make the axis x labels text wich will show the Client name just like a linkbutton and bind the "URL" column to it,
    does it possible ? and how can i do that even with alternate idea???
    its urgent for me , thanks.
    Regards,
    Q
    Sunday, December 14, 2008 10:48 AM

Answers

  • Hi Q,

    You can accomplish the datapoint label databinding by using a different databinding method. For example, in your Page_Load event handler, this will do the trick

    Chart1.Series[0].Points.DataBind(reader, "ClientName""Percentage""Label=Sessions"); 

    That will bind the Sessions column to the label of the datapoint.


    To click on the axis label and launch a corresponding URL requires a bit more finesse. There is no direct correlation between a datapoint and a label on the axis. So after you have bound your data, you can do something like this to accomplish what you want:

    foreach (CustomLabel label in Chart1.ChartAreas[0].AxisX.CustomLabels)  
    {  
        label.Url = string.Format("~/Users/{0}.aspx", label.Text);  



    http://blogs.msdn.com/magreer
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Tuesday, December 16, 2008 7:15 PM