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?

Member Avatar for LastMitch

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?

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.

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;
            }
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.