0

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.

Mark Corrigan
  • 544
  • 2
  • 11
  • 29
  • show your tried code. – Ajay Apr 18 '14 at 09:21
  • This sound like a jobe for [StripLines](https://msdn.microsoft.com/en-us/library/system.windows.forms.datavisualization.charting.stripline%28v=vs.110%29.aspx). See [here for an example](http://stackoverflow.com/questions/38958646/winforms-chart-how-to-enable-background-color-gauge/38959173#38959173) – TaW Aug 28 '16 at 19:05

2 Answers2

1

If you are using mschart

  1. Use a timer

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

jhyap
  • 3,779
  • 6
  • 27
  • 47
  • thanks for the reply, but will that change the entire background colour of the chart per tick or will it colour it in periods so you get a progressive colour change? – Mark Corrigan Apr 18 '14 at 09:09
  • yes, it will change the whole background color every tick. – jhyap Apr 18 '14 at 09:45
  • sorry, to be more specific the application requires a progressive of colour with time thus when viewing historic data a chart will appear to have a different colour depending on time of day. It's to represent RAG times used in power distribution – Mark Corrigan Apr 27 '14 at 18:55
  • 1
    It would be helpful if you can picture your idea inside your question to help us understand the problem better. – jhyap Apr 28 '14 at 00:26
0

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);
            }
        } 
daniele3004
  • 13,072
  • 12
  • 67
  • 75