Mark Corrigan
Mark Corrigan

Reputation: 554

Chart With Multiple BackColours c#

I'm looking to fill a c# chart with multiple backcolours in relation to timestamp.

Does anyone know of any code to do this or perhaps a method to implement the equivalent.

I thought about adding semi-transparent columns with appropriate widths but this seems a bit messy.

Any insight and ideas would be appreciated.

Upvotes: 0

Views: 107

Answers (2)

daniele3004
daniele3004

Reputation: 13960

This might be useful to you

       foreach (Series charts in chart1.Series)
        {
            foreach (DataPoint point in charts.Points)
            {
                if (point.AxisLabel == LibereStr)
                {
                    point.Color = Color.Green;
                    point.Font = new Font("Trebuchet MS", 9, FontStyle.Bold);
                    if (Libere == 0)
                    {
                        point.IsEmpty = true;
                    }
                }
                else if (point.AxisLabel == OccupateStr)
                {
                    point.Color = Color.Red;
                    point.Font = new Font("Trebuchet MS", 9, FontStyle.Bold);
                    if (Occupate == 0)
                    {
                        point.IsEmpty = true;
                    }
                }
                else if (point.AxisLabel == PrenotateStr)
                {
                    point.Color = Color.Violet;
                    point.Font = new Font("Trebuchet MS", 9, FontStyle.Bold);
                    if (Prenotate == 0)
                    {
                        point.IsEmpty = true;
                    }
                }
                point.Label = string.Format("{0:0} - {1}", point.YValues[0], point.AxisLabel);
            }
        } 

Upvotes: 0

jhyap
jhyap

Reputation: 3837

If you are using mschart

  1. Use a timer

  2. Every tick event, set back color to color you want

Upvotes: 1

Related Questions