This sampe code will plot a surface chart using data from a DataGridView.
 
Key aspects of this tutorial:
 
  • Change data in DataGridView and chart control will update automatically.
  • You can make a selection of cells in DataGridView and data will be highlighted in chart also.
  • You can rotate the chart in 3D moving the mouse while pressing left button.
  • You can move up/down any point using mouse (press CONTROL and drag the point in chart)
  • You can make a selection of points in chart pressing SHIFT and moving the mouse over.

Steps:

1. Create a new Windows application project (VB.NET)
2. Add Crossing Charts Library to the toolbox pallete and drag it to Form1.
3. Add a DataGridView control to the Form1.
4. Copy and paste de following code:

Code: [Select]
Imports System.Drawing.Drawing2D
Imports CrossingChartsLibrary
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  Dim rows As Integer = 20
  Dim cols As Integer = 20
  Dim hotspots(rows - 1) As ArrayList
  With DataGridView1
    .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
    .DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
    .RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders
    .Columns.Clear()
    For c As Integer = 1 To cols
      .Columns.Add("", c * 100)
    Next
    .Rows.Add(rows)
    Dim y As Integer = 0
    For r As Integer = 1 To rows
      .Rows(r - 1).HeaderCell.Value = CStr(r * 10)
      hotspots(r - 1) = New ArrayList
      For k As Integer = 1 To cols
        .Rows(r - 1).Cells(k - 1).Value = y
        y += Rnd() * 10 - 5
        If y < 0 Then y = 0
        hotspots(r - 1).Add("X-Axis = " & .Columns(k - 1).HeaderCell.Value & ", Z-Axis = " & .Rows(r - 1).HeaderCell.Value & ", Height = " & .Rows(r - 1).Cells(k - 1).Value)
      Next
    Next
  End With
  With CrossingCharts1
    ' Initialize chart control
    .AutoRefresh = False
    .BackStyle = STYLEBACKGROUND.STYLEBACKGROUND_GRADIENT
    .WallsBackStyle = STYLEWALLBACKGROUND.STYLEWALLBACKGROUND_SOLID
    .WallsBackColorPrincipal = Color.White
    .ShowDataTable = False
    .ShowValues = False
    .ShowLegend = False
    .Style = STYLE2D3D.STYLE3D_XYZ_SURFACE
    .HotSpotTooltips = hotspots
    ' Set some look and feel properties
    .SurfaceGradientType = SURFACE_GRADIENT_TYPE.TWO_COLORS_HUE_GRADIENT
    .SurfaceGradientHueStart = New HsbColorUtil(0, 0.5, 1)
    .SurfaceGradientHueEnd = New HsbColorUtil(360, 0.5, 1)
    .SetAllSeriesLineStyle(New Pen(Color.Black))
    ' Y-Axis-format
    .ShowYAxis = True
    .YAxisTitle = "Y-Axis"
    .YAxisDividersCount = 5
    .YAxisNumericFormat = "0"
    ' X-Axis-format
    .ShowXAxis = True
    .XAxisTitle = "X-Axis"
    .XAxisNumericFormat = "0"
    .XAxisDividersCount = 5
    .ShowDividersX = True
    ' Z-Axis-format
    .ShowZAxis = True
    .ZAxisTitle = "Z-Axis"
    .ZAxisDividersCount = 5
    .ShowDividersZ = True
    .ZAxisNumericFormat = "0"
    ' New property to enable selection
    .HotSpotOutlineEnabled = True
    ' New properties for databinding
    .DataSource = DataGridView1
    .DataSourceMode = DATASOURCE_SCHEME.XZ_HEADERS_Y_CELLS
    ' Paint chart
    .RefreshChart()
End With
End Sub
End Class

Results:

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