HighLow - Different colors for high and low

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
MVB
Newbie
Newbie
Posts: 7
Joined: Thu Dec 31, 2009 12:00 am

HighLow - Different colors for high and low

Post by MVB » Mon May 31, 2010 6:49 am

Hi,

I have a question about the different colors used for a HighLow Series.
I want to color the area where High > Low value green and the area where High < Low value red.

With the following code I get more or less the result:

Code: Select all

Steema.TeeChart.Styles.HighLow hl = new Steema.TeeChart.Styles.HighLow();
m_tchart.Series.Add(hl);

hl.Add(1, 10, 5);
hl.Add(2, 10, 8);
hl.Add(3, 10, 9);
hl.Add(4, 10, 12);
hl.Add(5, 10, 14);

hl.HighBrush.Color = System.Drawing.Color.Aquamarine;
hl.HighBrush.Visible = true;
hl.LowBrush.Color = System.Drawing.Color.LightCoral;
hl.LowBrush.Visible = true;
However, the red color already start from the point where the values ARE GOING TO cross (point 3 in my example). But in fact, I want to start the red color only from the cross point itself.
So, somewhere in the middle between 3 and 4 where the two lines actually cross. See screenshot.

Thanks for your help!
Marijke.
Attachments
highAndLowColor.png
Screenshot
highAndLowColor.png (32.62 KiB) Viewed 2840 times

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: HighLow - Different colors for high and low

Post by Sandra » Tue Jun 01, 2010 12:25 pm

Hello Marijke,

When you use HighLow Series, and you want to paint with different colors Low and High values, you need a point exactly of values intersection.
I recommend use function CrossPoints for calculate point intersection and two Region tools to paint values of the HighLow Series. Also, you should change the order of High and low points, because region tool works with high values for change its positions. Please, see next code, and check if it works as you want.

Code: Select all

       private Steema.TeeChart.Functions.CrossPoints crosssPoints1;
        private Steema.TeeChart.Tools.SeriesRegionTool region1, region2;
        private void InitializeChart()
        {
            tChart1.Aspect.View3D = false;

            Steema.TeeChart.Styles.HighLow hl = new Steema.TeeChart.Styles.HighLow(tChart1.Chart);
            Steema.TeeChart.Styles.Line line1= new Steema.TeeChart.Styles.Line();
            Steema.TeeChart.Styles.Line line2 = new Steema.TeeChart.Styles.Line();
            crosssPoints1 = new Steema.TeeChart.Functions.CrossPoints(tChart1.Chart);

            hl.Add(0, 5, 10);
            hl.Add(1, 8, 10);
            hl.Add(2, 9, 10);
            hl.Add(3, 12, 10);
            hl.Add(4, 14, 10);
            
            hl.LowBrush.Color = System.Drawing.Color.Aquamarine;
            hl.HighBrush.Color = System.Drawing.Color.LightCoral;
            tChart1.Legend.Visible = false;

            for (int i = 0; i < hl.Count; i++)
            {
                line1.Add(hl.XValues[i], hl.LowValues[i]);
            }

            line2.DataSource = new object[] { hl, line1 };
            line2.Function = crosssPoints1;

            region1 = new Steema.TeeChart.Tools.SeriesRegionTool(tChart1.Chart);
            region1.AutoBound = false;
            region1.UseOrigin = true;
            region1.Origin = line2.YValues[0];
            region1.LowerBound = hl.MinXValue();
            region1.UpperBound = line2.XValues[0];
            region1.Color = System.Drawing.Color.Aquamarine;
            region1.DrawBehindSeries = false;
            region1.Series = hl;

            region2 = new Steema.TeeChart.Tools.SeriesRegionTool(tChart1.Chart);
            region2.AutoBound = false;
            region2.UseOrigin = true;
            region2.Origin = line2.YValues[0];
            region2.LowerBound = line2.XValues[0];
            region2.UpperBound = hl.MaxXValue();
            region2.Color = System.Drawing.Color.LightCoral;
            region2.DrawBehindSeries = false;
            region2.Series = hl;
}
I hope will helps.

Thanks,
Best Regards,
Sandra Pazos / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply