locked
How to display mutiple fields on same axis on Bar Graph? RRS feed

  • Question

  • User-571580853 posted

    Hi all

    I have some data which needs to be displayed in Bar Graph. On X axis, I need to display department name, date. On Y axis I have the count of some incident within department. There are 3 categories associated with incident.

    Can someone provide me some pointers?

    cheers

    SiddNYork

    Wednesday, August 2, 2017 7:26 PM

All replies

  • User347430248 posted

    Hi Sidd@Nyork,

    you can try to refer example below.

    you can try to add 'YValueMembers' using array.

      //Give two columns of data to Y-axle
                Chart1.Series[0].YValueMembers = "Volume1";
                Chart1.Series[1].YValueMembers = "Volume2";
    
                //Set the X-axle as date value
                Chart1.Series[0].XValueMember = "Date";

    code:

     protected void Page_Load(object sender, EventArgs e)
            {
                DataTable dt = default(DataTable);
                dt = CreateDataTable();
    
    
                //Set the DataSource property of the Chart control to the DataTabel
                Chart1.DataSource = dt;
                Chart1.Series.Add("Volume");
                //Give two columns of data to Y-axle
                Chart1.Series[0].YValueMembers = "Volume1";
                Chart1.Series[1].YValueMembers = "Volume2";
    
                //Set the X-axle as date value
                Chart1.Series[0].XValueMember = "Date";
    
                //Bind the Chart control with the setting above
                Chart1.DataBind();
    
            }
            private DataTable CreateDataTable()
            {
                //Create a DataTable as the data source of the Chart control
                DataTable dt = new DataTable();
    
                //Add three columns to the DataTable
                dt.Columns.Add("Date");
                dt.Columns.Add("Volume1");
                dt.Columns.Add("Volume2");
    
                DataRow dr;
    
                for (int i = 0; i < 5; i++)
                {
                    //Add rows to the table which contains some random data for demonstration
                    dr = dt.NewRow();
                    dr["Date"] = "Jan" + i.ToString();
                    dr["Volume1"] = 3731;
                    dr["Volume2"] = 4101;
                    dt.Rows.Add(dr);
                }
    
                return dt;
            }
    <asp:Chart ID="Chart1" runat="server" Height="588px" Width="784px">
                <series>
                    <asp:Series Name="Series1">
                    </asp:Series>
                </series>
                <chartareas>
                    <asp:ChartArea Name="ChartArea1">
                    </asp:ChartArea>
                </chartareas>
            </asp:Chart>

    Output:

    Regards

    Deepak

    Thursday, August 3, 2017 6:15 AM