Custom Palette for Surface

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Yuri
Newbie
Newbie
Posts: 6
Joined: Fri Dec 09, 2011 12:00 am

Custom Palette for Surface

Post by Yuri » Sun Dec 18, 2011 8:22 pm

Hello,

We renew licence TeeChart for NET from version 4.0.2011.02083 to version 4.1.2011.10190. With the new version our old code does not work (Custom Palette for Surface: Surface.AddPalette(value, colour); ...). What can be changes in available code? (or show a sample of Custom Palette for Surface series)

Best Regards,
Yuri

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

Re: Custom Palette for Surface

Post by Sandra » Mon Dec 19, 2011 3:18 pm

Hello Yuri,

You are right.I have added it in bug list report with number [TF02015972]. We will try to fix it for next maintenance releases of TeeChart.Net. On the other hand, at the moment you can use next lines of code to solve your problem:

Code: Select all

        Steema.TeeChart.Styles.Surface surface;
        Color[] CustomPalette;
        public Form1()
        {
            InitializeComponent();   
             surface = new Surface(tChart1.Chart);
             InitializeChart();
        }
        private void InitializeChart()
        {
             Random rnd = new Random();
             surface.Pen.Visible = false;

             surface.UseColorRange = false;
             surface.UsePalette = true;
             surface.ColorEach = true;
             surface.IrregularGrid = true;
             for (int x = 0; x < 10; x++)
             {
                 for (int z = 0; z < 10; z++)
                 {
                        surface.Add(x, rnd.Next(100), z);
                 }
             }
        }
        private void button1_Click(object sender, EventArgs e)
        {
          CustomPalette = CreatePalette(surface);

          Steema.TeeChart.Themes.ColorPalettes.ApplyPalette(tChart1.Chart, CustomPalette);
          tChart1.Refresh();
        }
        private Color [] CreatePalette(Steema.TeeChart.Styles.Series s)
        {
            Color[] Palette1 = new Color[s.Count];
            for (int t = 0; t < s.Count; t++)
            {
                if (t < 25)
                {
                    Palette1[t] = Color.Red;
                }
                else if (t > 25 && t < 50)
                {
                    Palette1[t] = Color.Blue;
                }
                else if (t > 50 && t < 75)
                {
                    Palette1[t] = Color.Green;
                }
                else
                {
                    Palette1[t] = Color.White;
                }
            }
            return Palette1;
        }      
    }
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

Yuri
Newbie
Newbie
Posts: 6
Joined: Fri Dec 09, 2011 12:00 am

Re: Custom Palette for Surface

Post by Yuri » Sun Dec 25, 2011 7:49 pm

Hello Sandra,

Method with surface. ColorEach does not approach to us. We need to synchronise Contour.Levels and Surface.Palette by value and color (Contour and Surface are different representations of the same phenomenon).
We need to have possibility to set custom levels for a colouring of the series and display in a legend. The series contains decimal values, but in a legend integer values should be displayed.
What can you recommend?

Best Regards,
Yuri

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

Re: Custom Palette for Surface

Post by Sandra » Tue Dec 27, 2011 3:15 pm

Hello Yuri,

Ok. In your case, I recommend add ColorGrid's custom palette as described here. Can you tell if it works as you expect?

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

Yuri
Newbie
Newbie
Posts: 6
Joined: Fri Dec 09, 2011 12:00 am

Re: Custom Palette for Surface

Post by Yuri » Wed Dec 28, 2011 11:58 pm

Hello Sandra,

Replacing Surface with ColorGrid does not approach to us. The code by your link is similar to ours code, but in version 4.1.2011.10190 it does not work. We will roll back to version 4.0.2011.02083

Best Regards,
Yuri

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

Re: Custom Palette for Surface

Post by Sandra » Thu Dec 29, 2011 12:13 pm

Hello Yuri,

I check next code using last version of TeeChart.Net and works fine for me, you only needed add IrregularGrid=true.

Code: Select all

    public Form1()
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.ColorGrid colorgrid1;
        private void InitializeChart()
        {
            colorgrid1 = new ColorGrid(tChart1.Chart);
            // populate series with data
            tChart1.Aspect.View3D = false;
            // populate series with data
            colorgrid1.IrregularGrid = true;
            for (int i = -5; i < 5; i++)
                for (int j = -3; j < 5; j++)
                    colorgrid1.Add(i, 2.5 * Math.Sin(Math.PI * Math.Pow(i * j, 2) / 10.0), j);
            // create custom palette
            colorgrid1.UsePalette = true;
            colorgrid1.UseColorRange = false;
            colorgrid1.ClearPalette();
            // beige from -2.5 to -2.0
            colorgrid1.AddPalette(-2.0, Color.Beige);
            // white from -2.0 to 0.0
            colorgrid1.AddPalette(0.0, Color.White);
            // blue from 0.0 to to to 2.0
            colorgrid1.AddPalette(2.0, Color.Blue);
            // violet from 2.0 to 2.5
            colorgrid1.AddPalette(2.5, Color.Violet);
        }
Can you tell us if it works as you expected? If it doesn't work as you want, please send us a simple example we can reproduce your problem with palette, because we can try to find a good solution for you.

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

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

Re: Custom Palette for Surface

Post by Sandra » Mon Jan 02, 2012 2:46 pm

Hello Yuri,

I inform you about some questions:

First, I inform you that the bug with number [TF02015972] is already fixed for new maintenance release that is about to leave, but at the moment, you can change the next lines of code of Method CheckPaletteEmpty, you can find in the Custom3DPalette.cs file, of your source code. See next do next:

Code: Select all

 private void CheckPaletteEmpty()
    {
			if ((Count > 0) && (palette.Count == 0)) //CDI TF02015972 - can always call ClearPalette() for below, no?
      //if ((Count > 0)) //CDI if palette created by new values added, palette doesn't change.
        CreateDefaultPalette(iPaletteSteps);
    }
How you can see, in previous code you only have commented the second IF and discommended the first IF.

Second, I have apologize you, because I forgot answer your question about Legend Items. I have made a simple code, where I round the Double Values of Legend for convert to Int values. I think you can do something similar as next code:

Code: Select all

   public Form1()	
        {
            InitializeComponent();
            InitializeChart();
        }
        Steema.TeeChart.Styles.Surface surface1;
        private void InitializeChart()
        {
            surface1 = new Surface(tChart1.Chart);
            // populate series with data
            tChart1.Aspect.View3D = false;
            // populate series with data
           surface1.IrregularGrid = true;
           for (int i = -5; i < 5; i++)
               for (int j = -3; j < 5; j++)
                   surface1.Add(i, 2.5 * Math.Sin(Math.PI * Math.Pow(i * j, 2) / 10.0), j);
            tChart1.GetLegendText += new GetLegendTextEventHandler(tChart1_GetLegendText);
           
        }
        void tChart1_GetLegendText(object sender, GetLegendTextEventArgs e)
        {
                if ((Convert.ToDouble(e.Text) % 2) != 0)
                {
                    e.Text = Math.Round(Convert.ToDouble(e.Text)).ToString();
                }
         
        }
Can you tell us if previous code works as you expected? If it doesn't works as you expected please let me know, and explain us what you want achieve, exactly.

Finally, I have apologize you, because I made a simple code using a ColorGrid, so, I understood you would it works for a ColorGrid, too, sorry.

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

Yuri
Newbie
Newbie
Posts: 6
Joined: Fri Dec 09, 2011 12:00 am

Re: Custom Palette for Surface

Post by Yuri » Tue Jan 03, 2012 2:01 pm

Hello Sandra,

Thanks, with changes in Custom3DPalette.cs file of source code our code works as we expected.

Best Regards,
Yuri

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

Re: Custom Palette for Surface

Post by Sandra » Tue Jan 03, 2012 2:49 pm

Hello Yuri,

I am glad that the solution works as you expect. :)

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