Tutorial 56: XYZ surface selection & modifying data! (C#)
« on: February 05, 2016, 01:41:02 AM »
This sample code will plot a surface chart and will show how to use the mouse to make selections and modify the data:
 
Steps:

1. Create a new Windows application project (C#) and name it SurfaceChartSelection.
2. Add Crossing Charts Library to the toolbox palette and drag it to Form1. Name it "chart".
3. Add a DataGridView control to the Form1.
4. Copy and paste de following code:

Code: [Select]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CrossingChartsLibrary;
 
namespace SurfaceChartSelection {
   public partial class Form1 : Form {
      public Form1() {
         InitializeComponent();
      }
      private void Form1_Load(object sender, EventArgs e) {
         // Initialize chart control
         chart.AutoRefresh = false;
         chart.BackStyle = STYLEBACKGROUND.STYLEBACKGROUND_SOLID;
         chart.BackColor = Color.Black;
         chart.WallsBackStyle = STYLEWALLBACKGROUND.STYLEWALLBACKGROUND_TRANSPARENT;
         chart.ShowDataTable = false;
         chart.ShowValues = false;
         chart.ShowLegend = false;
         chart.TitleColor = Color.White;
         chart.ZoomEnabled = true;
         // Set some look and feel properties
         chart.SurfaceGradientType = SURFACE_GRADIENT_TYPE.LIST_OF_COLORS_LINEAR_GRADIENT;
         chart.SurfaceGradientColors = new List<Color>();
         chart.SurfaceGradientColors.AddRange(new Color[] { Color.Red, Color.Brown, Color.Yellow, Color.White, Color.Blue });
         chart.SetAllSeriesLineStyle(new Pen(Color.White));
         chart.HotSpotOutlineStyle = new Pen(Color.Red, 5);
         chart.PointSize = 8;
         chart.GridLineStyle = new Pen(Color.White);
 
         // Y-Axis-format
         chart.ShowYAxis = true;
         chart.YAxisTitle = "Y-Axis";
         chart.YAxisDividersCount = 5;
         chart.YAxisNumericFormat = "0";
         chart.YAxisScaleMode = SCALEMODE.SCALEMODE_AUTOMATIC;
         chart.ShowDividersY = false;
       
         // X-Axis-format
         chart.ShowXAxis = true;
         chart.XAxisTitle = "X-Axis";
         chart.XAxisNumericFormat = "0";
         chart.XAxisDividersCount = 5;
         chart.ShowDividersX = false;
         chart.XAxisColor = Color.White;
         chart.XAxisScaleMode = SCALEMODE.SCALEMODE_AUTOMATIC;
         chart.XAxisDirection = -1;
       
         // Z-Axis-format
         chart.ShowZAxis = true;
         chart.ZAxisTitle = "Z-Axis";
         chart.ZAxisDividersCount = 5;
         chart.ShowDividersZ = false;
         chart.ZAxisNumericFormat = "0";
         chart.ZAxisScaleMode = SCALEMODE.SCALEMODE_AUTOMATIC;
         chart.ZAxisColor = Color.White;
         chart.Style = STYLE2D3D.STYLE3D_XYZ_SURFACE;
         SeriesFactory sf = new SeriesFactory();
         for (int x = 0; x < 25; x++) {
            for (int y = 0; y < 25; y++) {
                     sf.AddPoint(x, (float)(Math.Cos((x - 12) / 20.0) * Math.Cos((y - 12) / 20.0) * 10.0), y);
            }
         sf.NewSerie(); // <--- Quad surface needs points organized into series
         }
         sf.ApplyTo(chart);
         chart.RefreshChart();
   }
 
   private void btShowSelection_Click(object sender, EventArgs e) {
      chart.SelectionAddItem(10, 10);
   }
 
   private void btHideSelection_Click(object sender, EventArgs e) {
      chart.SelectionClear();
   }
 
   private void btSelectionReduce_Click(object sender, EventArgs e) {
      chart.SelectionReduce();
   }
 
   private void btDeselectOne_Click(object sender, EventArgs e) {
      chart.SelectionRemoveItem(10, 10);
   }
 
   private void btMoveSelectionLeft_Click(object sender, EventArgs e) {
      chart.SelectionMoveLeft(1, true);
   }
 
   private void btMoveSelectionRight_Click(object sender, EventArgs e) {
      chart.SelectionMoveRight(1, true);
   }
 
   private void btMoveSelectionUp_Click(object sender, EventArgs e) {
      chart.SelectionMoveUp(1, true);
   }
 
   private void btMoveSelectionDown_Click(object sender, EventArgs e) {
      chart.SelectionMoveDown(1, true);
   }
 
   private void btSelectionGrow_Click(object sender, EventArgs e) {
      chart.SelectionGrow(1);
   }
 
   private void btSelectionIncrease_Click(object sender, EventArgs e) {
      chart.SelectionOpAdd(0, 1);
   }
 
   private void btSelectionDecrease_Click(object sender, EventArgs e) {
      chart.SelectionOpAdd(0, -1);
   }
 
   private void btRotateLeft_Click(object sender, EventArgs e) {
      chart.YAxisAngle-=0.02F;
      chart.RefreshChart();
   }
 
   private void btRotateRight_Click(object sender, EventArgs e) {
      chart.YAxisAngle+=0.02F;
      chart.RefreshChart();
   }
 
   }
}

Results:

« Last Edit: February 16, 2016, 11:30:14 AM by CrossingCharts »