简体   繁体   中英

asp.net column chart coloring of each column in c#

im using c# for first time in a asp.net website, in which i am creating charts. i have created a column chart- 2D, and the code goes like this,

protected void chrtTickets_Load(object sender, EventArgs e)
        {
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {

                connection.Open();


                SqlCommand cmmd6 = new SqlCommand("getHowTicketsLoggedChart", connection);
                cmmd6.CommandType = CommandType.StoredProcedure;


                DataSet ds1 = new DataSet();

                SqlDataAdapter dad = new SqlDataAdapter(cmmd6);

                dad.Fill(ds1);

                chrtTickets.DataSource = ds1;


                chrtTickets.Series["Series1"].XValueMember = "MonYYYY";

                chrtTickets.Series["Series1"].YValueMembers = "aa";


                chrtTickets.DataBind();
                connection.Close();


            }
        }

but i have the stored procedure which returns me another field "Description" along with MonYYYy and aa as they are used in xaxis and yaxis.

but according to the "description" field value say: email, phone, portal. i want to assign a different color to each column depending upon each row's description value, if its Email-> red and so on etc.

can anyone please guide me through this?

what i mean is my data will be be like this: so i will not know what will be color type value in advance, this is the table values returned to me from db by my stored procedure.

color type| y-axiz value | x-axis


Email Connector| 24| Dec 2011 Phone | 32 | Dec 2011 Email Connector |643 | Jan 2012 Internal | 32 | Jan 2012 Phone |455| Jan 2012 Portal |2 | Jan 2012 Sales Order| 2| Jan 2012

it cold be one of the 5 types ex. email, portal but many x-axis value.

datapoints will not be known. they are dynamic.

you can try this it should randomly chose a color for the next bar

Color[] colors = new Color[] { Color.Red, Color.Green, Color.Wheat, Color.Gray. Color.Black,  Color.Blue};
foreach (Series series in chrtTickets.Series)
{
    foreach (DataPoint point in series.Points)
    {
        Random random = new Random();
        int randomNumber = random.Next(0, 5);
        point.LabelBackColor = colors[ randomNumber];
    }
}

here is main article http://forums.asp.net/t/1652369.aspx/1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM