在c#asp.net柱形图着色每列 [英] asp.net column chart coloring of each column in c#

查看:110
本文介绍了在c#asp.net柱形图着色每列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

读音字使用C#首次在asp.net网站,其中我创建的图表。
我创建了一个列chart- 2D和code是这样的,

i m 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();


            }
        }

但我有这个存储过程,它们是在x轴和Y轴使用返回我的另一场描述与MonYYYy和AA一起。

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.

颜色类型| Y型axiz值| x轴

color type| y-axiz value | x-axis

电子邮件连接器| 24 | 2011年12月
电话| 32 | 2011年12月
电子邮件连接器| 643 | 2012年1月
内部| 32 | 2012年1月
电话| 455 | 2012年1月
门户| 2 | 2012年1月
销售订单| 2 | 2012年1月

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

是冷是5种EX​​之一。电子邮件,门户网站但许多X轴值。

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];
    }
}

下面是文章主要 http://forums.asp.net/t/1652369。 ASPX / 1

这篇关于在c#asp.net柱形图着色每列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆