in

C1 Community

ComponentOne Community is a free source for developers and help authors to collaborate and communicate.

How do you PLOT Data from an array on XY chart?

Last post 06-16-2008 5:57 PM by C1_GregL. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 06-04-2008 12:44 PM

    How do you PLOT Data from an array on XY chart?

    I need a code sample of how to get data to appear on an XY plot chart (not component ones samples).   The data is given to me in an array  arrGraphData that I set as the datasource - Chart1.DataSource = arrGraphData.   After this line of code I can see my data within Chart1.DataSource a sample of the data is below:

     {Length=150}    (0,0): ""    (0,1): "Day 1"    (0,2): "Day 2"    (0,3): "Day 3"    (0,4): "Day 4"    (0,5): "Day 5"    (1,0): " 0 "    (1,1): ""    (1,2): ""    (1,3): ""    (1,4): ""    (1,5): ""    (2,0): " 1 "    (2,1): ""    (2,2): ""    (2,3): ""    (2,4): ""    (2,5): ""    (3,0): " 2 "    (3,1): 5 {Integer}    (3,2): 5 {Integer}    (3,3): 8 {Integer}    (3,4): 3 {Integer}    (3,5): 5 {Integer}    (4,0): " 3 "    (4,1): ""    (4,2): ""    (4,3): ""    (4,4): ""    (4,5): ""    (5,0): " 4 "    (5,1): ""    (5,2): ""    (5,3): ""    (5,4): ""    (5,5): ""    (6,0): " 5 "    (6,1): ""    (6,2): ""    (6,3): ""    (6,4): ""    (6,5): ""    (7,0): " 6 "    (7,1): 75 {Integer}    (7,2): 60 {Integer}    (7,3): 82 {Integer}    (7,4): 67 {Integer}    (7,5): 89 {Integer}    (8,0): " 7 "    (8,1): 109 {Integer}    (8,2): 79 {Integer}    (8,3): 96 {Integer}    (8,4): 85 {Integer}    (8,5): 89 {Integer}

    But the chart does not reflect the data.  How do I get this data to appear on the chart?

    Filed under: ,
  • 06-11-2008 1:19 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 498

    Re: How do you PLOT Data from an array on XY chart?

    To load an array as the datapoints you would do something like this:

    1. C1Chart1.Reset()
    2. C1Chart1.ChartGroups(0).ChartData.SeriesList.AddNewSeries()
    3. Dim arr(3) As PointF
    4. arr(0) = New PointF(2, 5)
    5. arr(1) = New PointF(4, 3)
    6. arr(2) = New PointF(6, 8)
    7. arr(3) = New PointF(7, 1)
    8. C1Chart1.ChartGroups(0).ChartData.SeriesList(0).PointData.CopyDataIn(arr)

    You can also set arrays for X and Y individually

    1. C1Chart1.ChartGroups(0).ChartData.SeriesList(0).X.CopyDataIn(Array)

    To use a DataTable structure:

    1. C1Chart1.Reset()
    2. 'Create DataTable 
    3. Dim dt As DataTable
    4. dt = New DataTable("Points")
    5. Dim dr As DataRow
    6. Dim xcol As New DataColumn("XCOL")
    7. xcol.DataType = System.Type.[GetType]("System.Double")
    8. dt.Columns.Add(xcol)
    9. Dim ycol As New DataColumn("YCOL")
    10. ycol.DataType = System.Type.[GetType]("System.Double")
    11. dt.Columns.Add(ycol)
    12. Dim rnd As New Random()
    13. For i As Integer = 0 To 9
    14. dr = dt.NewRow()
    15. dr("XCOL") = rnd.Next(0, 100)
    16. dr("YCOL") = rnd.Next(0, 100)
    17. dt.Rows.Add(dr)
    18. Next
    19. C1Chart1.DataSource = dt
    20. Dim data As ChartData = C1Chart1.ChartGroups(0).ChartData
    21. Dim ds As ChartDataSeries = data.SeriesList.AddNewSeries()
    22. ds.X.DataField = "XCOL"
    23. ds.Y.DataField = "YCOL"

    hope that helps,
    Greg L

    Filed under: ,
  • 06-16-2008 11:37 AM In reply to

    Re: How do you PLOT Data from an array on XY chart?

    Thanks for your response regarding my question on plotting an XY chart.  I am still having difficulty.  The data is given to me in a 2D array -- rows 0 thru 5 with the first element in each row containing the text "Day 1"  through "Day 5".  Using our previous chart software, this text shows across the bottom of the chart below the X axis as a legend.  The first element of each column is a text number that appears on the X axis and is used as the X coordinate.  The rest of the integers in each column is the Y coordinate.  For example:

    array(7,0) = "6" which is the number that should appear on the X axis

    array(7,1) = 75 which is the Y value (the X value being 6) so the point would be 6,75

    array(7,2) = 60  so the point value would be 6,60

    C1Chart1.ChartGroups(0).ChartData.SeriesList(0).X.CopyDataIn(array) gave me the error that an array is required.  Not quite sure what this means since I was giving it an array.  Also, is SeriesList always 0 or should it increase to 5 since I have 5 series of data?  Thanks! 

  • 06-16-2008 5:57 PM In reply to

    • C1_GregL
    • Top 10 Contributor
    • Joined on 06-11-2007
    • Pittsburgh PA
    • Posts 498

    Re: How do you PLOT Data from an array on XY chart?

    You won't be able to simply load this 2d array because it's too ambiguous.  C1Chart would not know which rows are for X and which are for Y, plus you have your series text in there too.  So when you call CopyDataIn you should pass it one row of your 2d array and not the entire array.  1 row for each dataseries, and 1 row containing the X values.  Copy the X value row into each SeriesList(i).X and then copy each Y value row into its SeriesList(i).Y.  Each row is like a subarray.  You will first need to add 5 data series; one for each day. 

    here's a smaller sample

    1. C1Chart3.Reset()
    2. C1Chart3.ChartGroups(0).ChartData.SeriesList.AddNewSeries()
    3. C1Chart3.ChartGroups(0).ChartData.SeriesList.AddNewSeries()
    4. C1Chart3.ChartGroups(0).ChartData.SeriesList.AddNewSeries()
    5. Dim array()() As Integer = New Integer(3)() {}
    6. array(0) = New Integer(3) {1, 2, 3, 4} 'X values for all Series
    7. array(1) = New Integer(3) {3, 5, 7, 9} 'Y values for Series 0
    8. array(2) = New Integer(3) {5, 6, 1, 7} 'Y values for Series 1
    9. array(3) = New Integer(3) {3, 2, 0, 4} 'Y values for Series 2
    10. C1Chart3.ChartGroups(0).ChartData.SeriesList(0).X.CopyDataIn(array(0))
    11. C1Chart3.ChartGroups(0).ChartData.SeriesList(1).X.CopyDataIn(array(0))
    12. C1Chart3.ChartGroups(0).ChartData.SeriesList(2).X.CopyDataIn(array(0))
    13. C1Chart3.ChartGroups(0).ChartData.SeriesList(0).Y.CopyDataIn(array(1))
    14. C1Chart3.ChartGroups(0).ChartData.SeriesList(1).Y.CopyDataIn(array(2))
    15. C1Chart3.ChartGroups(0).ChartData.SeriesList(2).Y.CopyDataIn(array(3))

    hope that helps,
    Greg L

Page 1 of 1 (4 items)
Contact ComponentOne: 1.800.858.2739 ©1987-2008 ComponentOne LLC All Rights Reserved.