Page 1 of 1

ColorGrid

Posted: Tue Jun 13, 2006 11:54 am
by 8123141
I want to display certain values in a ColorGrid. Therefore, I wrote the following code:

colorGrid1.ClearPalette();

colorGrid1.AddPalette(1.0, Color.Red);
colorGrid1.AddPalette(1.5, Color.Blue);
colorGrid1.AddPalette(2.0, Color.Black);

this.colorGrid1.BeginUpdate();
this.colorGrid1.Clear();

double[] x = {1.0, 1.5, 1.0};
double[] y = {1.0, 1.5, 1.5};
double[] z = {1.0, 1.5, 2.0};

this.colorGrid1.Add(x, y, z);
this.colorGrid1.CheckOrder();
this.colorGrid1.EndUpdate();

As you can see, the z-value
* 1.0 should be displayed red
* 1.5 should be displayed blue
* 2.0 should be displayed black

Unfortunately my code does not work. The program crashes down to a System.IndexOutOfRangeException.

Any ideas?

Posted: Thu Jun 15, 2006 11:19 am
by narcis
Hi dotnetjunkee,

This is because ColorGrid series is not being properly populated. Please my reply on this topic on how to populate all series inherited from Custom3D series. For example, the examples below work fine:

Code: Select all

    private void Form1_Load(object sender, EventArgs e)
    {

      double[] x = { 1.0, 1.0, 1.0 };
      double[] y = { 1.0, 1.5, 1.5 };
      double[] z = { 1.0, 2.0, 3.0 };

      this.colorGrid1.Add(x, y, z);

      colorGrid1.UseColorRange = false;
      colorGrid1.UsePalette = true;
      colorGrid1.PaletteSteps = 3;
      colorGrid1.ClearPalette();

      colorGrid1.AddPalette(1.0, Color.Red);
      colorGrid1.AddPalette(1.5, Color.Blue);
      colorGrid1.AddPalette(2.0, Color.Black); 
    }
or

Code: Select all

    private void Form1_Load(object sender, EventArgs e)
    {
      Random rnd = new Random();
      double[] xValues = new double[36];
      double[] yValues = new double[36];
      double[] zValues = new double[36];
      int count = 0;

      for (double x = 0; x < 6; ++x)
      {
        for (double y = 0; y < 6; ++y)
        {
          xValues[count] = y;
          zValues[count] = x;
          yValues[count] = rnd.Next(3);
          ++count;
        }
      }

      colorGrid1.Add(xValues, yValues, zValues);

      colorGrid1.UseColorRange = false;
      colorGrid1.UsePalette = true;
      colorGrid1.PaletteSteps = 3;
      colorGrid1.ClearPalette();

      colorGrid1.AddPalette(1.0, Color.Red);
      colorGrid1.AddPalette(1.5, Color.Blue);
      colorGrid1.AddPalette(2.0, Color.Black); 
    }