0

ae11c10b62ad1537f03030637438cc85

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                setDropDownList();
            bcChart.Series["Series1"].Points.DataBindXY(getDate(), getAmount());
            bcChart.Series["Series1"].LegendText = "#VALX - RM #VALY{N2}";
        }

As you can see my bar graph is displaying 2 items,
but how come the legend only show one items and i can't display the legend text as i defined in code behind.
It work fine in Pie Chart, but when turn to Bar Chart it no more working.
And yet, how can i display 2 items in multiple colour?

2
Contributors
3
Replies
12
Views
3 Years
Discussion Span
Last Post by gahhon
0

It work fine in Pie Chart, but when turn to Bar Chart it no more working.
And yet, how can i display 2 items in multiple colour?

@gahhon

Is this an excel sheet data?

0

Nope. All of the data is came from database and bind into it.
getDate() is a methods used to retrieve xValues whereas the getAmount() is used to retrieve yValues.

1

Set the Chart

        protected void setChart()
        {
            bcChart.Series[0].IsValueShownAsLabel = true;
            bcChart.Series[0].Label = "RM #VALY{N2}";
            bcChart.Series[0].Points.DataBindXY(getDate(), getAmount());
            foreach (Series series in bcChart.Series)
                foreach (DataPoint point in series.Points)
                    point.Color = randomColor.NextColor();
        }

Generate Random Color

        //Generate A Random Color
        public class RandomColor
        {
            Type colorType = typeof(System.Drawing.Color);
            PropertyInfo[] proInfos;
            Random rand = new Random();

            //Constructor
            public RandomColor()
            {
                proInfos = colorType.GetProperties(BindingFlags.Static | BindingFlags.Public);
            }

            //Get Next Color
            public Color NextColor()
            {
                Color ColorName = Color.FromName(proInfos[rand.Next(0, proInfos.Length)].Name);
                return ColorName;
            }
        }
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.