ComponentOne Chart 8.0 for ActiveX
Copying Data

 

Copying Data

Before you can create a chart, you must provide it with data. ComponentOne Chart provides users with 6 different methods that allow you to copy data arrays directly to and from the chart, making it easy to quickly create chart data. These methods pass data using OLE SafeArrays. To use these methods, your development environment must support SafeArrays, either directly (as in Microsoft Visual Basic), or using a special mechanism (such as Variant arrays). For more information, refer to your development environment documentation.

The following copying data methods are defined by the Chart2DData object:

CopyXVectorIn(value,array), CopyXVectorOut(value,array)

Copies the X values for a specified series of data either from an array into a chart (CopyXVectorIn), or from a chart into an array (CopyXVectorOut). value is the series number for the data that is to be copied. array is either the name of the array where the X values are stored (CopyXVectorIn), or the name of the array where the X values are copied (CopyXVectorOut). Note that to use CopyXVectorIn and CopyXVectorOut, the array must be a one-dimensional array of singles, doubles, longs, integers, or dates. ComponentOne Chart provides the ability to pass zero-based and one-based arrays.

CopyXVectorIn and CopyXVectorOut return True when the copy is successful, False otherwise.

The following example uses the CopyXVectorIn method to copy the fourth series from an array "MyArray":

Dim MyArray (1 to 10) as Double
Chart2d1.ChartGroups(1).Data.CopyXVectorIn 1,MyArray

CopyYVectorIn(value,array), CopyYVectorOut(value,array)

Copies the Y values for a specified series of data either from an array into a chart (CopyYVectorIn), or from a chart into an array (CopyYVectorOut). value is the series number for the data that is to be copied. array is the name of the array where the Y values are stored (CopyYVectorIn) where the Y values are copied (CopyYVectorOut). Note that to use CopyYVectorIn and CopyYVectorOut, the array must be a one-dimensional array of singles, doubles, longs or integers. ComponentOne Chart provides the ability to pass zero-based and one-based arrays.

CopyYVectorIn and CopyYVectorOut return True when the copy is successful, False otherwise.

CopyYArrayIn(array), CopyYArrayOut(array)

Copies an array of Y data to multiple series (CopyYArrayIn) or from multiple series into an array (CopyYArrayOut). array is a two-dimensional array of singles, doubles, longs or integers where the data is located or is to be copied. The common X values are usually set with CopyXVectorIn, and the Y values for all series can be set with CopyYArrayIn. Note that to use this method the size of the array passed must match the number of series and points declared by NumSeries and NumPoints. ComponentOne Chart provides the ability to pass zero-based and one-based arrays. Arrays must be declared with the number of points as its first element, and the number of series as its second element. Note that to use CopyYArrayIn or CopyYArrayOut, your data must be in Array format. Otherwise, use CopyYVectorIn.

Example

Adding a lot of points (in the following example, four series of 10,000 points each) can be quite slow. The chart must add each point to the chart as it is generated to copy data arrays directly to and from the chart, making it easy to quickly create chart data.

The following code example uses the CopyYArrayIn method to quickly copy an entire array of data to the chart. The array passed is a two-dimensional array of singles, doubles, longs or integers. Note that to use this method the size of the array passed must match the number of series and points declared by NumSeries and NumPoints. Arrays must be declared with the number of points as its first dimension element, and the number of series as its second element.

Sub Main

' Setup the chart so it will display correctly

Chart2D1.ChartGroups(1).Styles(1).Symbol.Size = 0Chart2D1.ChartGroups(1).Styles(2).Symbol.Size = 0Chart2D1.ChartGroups(1).Styles(3).Symbol.Size = 0Chart2D1.ChartGroups(1).Styles(4).Symbol.Size = 0

With Chart2D1.ChartGroups(1).Data    .IsBatched = True    .NumSeries = 4    .NumPoints(1) = 10000

End With

' Declare a variableDim Yarray(1 To 10000, 1 To 4) As Double

' Generate some data, and add it to the chartFor j = 1 To 4

With Chart2D1.ChartGroups(1).Data    .x(1, j) = j

    For i = 1 To 10000    ‘Create a random number for our data    Yarray(i, j) = (i / j) + (0.5 * Int(((i / j) * Rnd) + 1))    Next i

End WithNext j

Chart2D1.ChartGroups(1).Data.CopyYArrayIn (Yarray)Chart2D1.ChartGroups(1).Data.IsBatched = False

End Sub

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback