in

C1 Community

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

Creating a chart, source code requested.

Last post 02-15-2008 6:49 PM by Timothy1. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-11-2008 12:26 PM

    Creating a chart, source code requested.

     
     
    The linked excel spreadsheet, DATA worksheet shows the type of data I would be using, the first column is a Date Time field in, I believe, Julian format.  The second column is temperature in Celcius.  The GRAPH worksheet shows the type of chart I would like to create.
     
    Can anyone help me with the source code that would create the Chart from the Data in this excel sample?
  • 02-13-2008 2:30 AM In reply to

    Re: Creating a chart, source code requested.

    You can try the code given below:
     
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Dim dv As DataView = Me.SqlDataSource1.Select(New DataSourceSelectArguments())

    ' clear data series collection

    Dim dsc As ChartDataSeriesCollection = Me.C1WebChart1.ChartGroups(0).ChartData.SeriesList

    dsc.Clear()

    ' add unit price series

    Dim ds As ChartDataSeries = dsc.AddNewSeries()

    'Dim ds As ChartDataSeries = Me.C1WebChart1.ChartGroups(0).ChartData.SeriesList(0)

    'ds.AutoEnumerate = true' (in case you don't want to set the X values)

    'ds.X.DataField = "OrderDate"

    'ds.Y.DataField = "OrderID"

    ds.PointData.Length = dv.Count

    Dim i As Integer

    For i = 0 To dv.Table.Rows.Count - 1

    ds.X(i) = dv(i)("OrderDate")

    ds.Y(i) = dv(i)("OrderID")

    Next i

    ds.X.DataType = GetType(System.DateTime())

    Me.C1WebChart1.DataSource = dv

    Me.C1WebChart1.DataBind()

    End Sub

    Regards,

    Patrick

    <Timothy1> wrote in message news:201809@10.0.1.98...
     
     
    The linked excel spreadsheet, DATA worksheet shows the type of data I would be using, the first column is a Date Time field in, I believe, Julian format.  The second column is temperature in Celcius.  The GRAPH worksheet shows the type of chart I would like to create.
     
    Can anyone help me with the source code that would create the Chart from the Data in this excel sample?


    http://helpcentral.componentone.com/cs/forums/p/74270/201809.aspx#201809

  • 02-14-2008 6:34 PM In reply to

    Re: Creating a chart, source code requested.

    Patrick,

    Many thanks, that looks very much like what I am after!

     Now if I can figure out how to get rid of the blue spots for data points and format the Axis X columns to come out as dates....

     :)

  • 02-15-2008 3:55 AM In reply to

    Re: Creating a chart, source code requested.

    If you want to get rid of the blue spots on the DataPoints on the series then you will have to set the Shape in the SymbolStyle property for a series to be none.
     

    protected void Page_Load(object sender, EventArgs e)

    {

    this.C1WebChart1.ChartGroups[0].ChartData.SeriesList[1].SymbolStyle.Shape = C1.Win.C1Chart.SymbolShapeEnum.None;

    }

    Regards,

    Patrick

    <Timothy1> wrote in message news:201967@10.0.1.98...

    Patrick,

    Many thanks, that looks very much like what I am after!

     Now if I can figure out how to get rid of the blue spots for data points and format the Axis X columns to come out as dates....

     :)



    http://helpcentral.componentone.com/cs/forums/p/74270/201967.aspx#201967

  • 02-15-2008 6:49 PM In reply to

    Re: Creating a chart, source code requested.

    Patrick,

     Thank you again.  I had figured out that I could set the SymbolStyle.Color = Color.Transparent but setting the shape to none is much better.

     In just playing around with the code to see if I can get the chart component to work I was creating my dataset programatically like so:

    Dim dATAs As New DataSet
    Dim dt As New DataTable
    dt.TableName = "DATA"
    dt.Columns.Add(New DataColumn("DT", GetType(System.DateTime)))
    dt.Columns.Add(New DataColumn("TEMP", GetType(System.Double)))
    dATAs.Tables.Add(dt)
    Dim dr As DataRow
    dr = dATAs.Tables("DATA").newrow
    dr("DT") = "3/6/07 12:07 AM"
    dr("TEMP") = "3.195"
    dATAs.Tables("DATA").rows.add(dr)
    dr = dATAs.Tables("DATA").newrow
    dr("DT") = "3/6/07 12:10 AM"
    dr("TEMP") = "3.221"
    dATAs.Tables("DATA").rows.add(dr)
    and so on and so forth...  (2300 rows) Obviously I wouldn't do this in production use.

     I found that when I added the Date data like I had it in the excel spreadsheet example on our ftp site (the first date value was 39147.0052083333) I was geting datatype mismatch errors from vb.net.  To fix it I formated them as dates as in the example dataset above.  The weird thing is that the chart component is returning 39145 instead of 3/6/2007 12:07 AM!

    Here is my code as I (barely) modified it from your example:

    Protected Sub setupchart()

    Dim dv As New DataView(dATAs.Tables("DATA"))

    Dim dsc As C1.Win.C1Chart.ChartDataSeriesCollection = _

    c1Chart.ChartGroups(0).ChartData.SeriesList

    dsc.Clear()

    Dim ds As C1.Win.C1Chart.ChartDataSeries = dsc.AddNewSeries()

    ds.PointData.Length = dv.Count

    'ds.Display = C1.Win.C1Chart.SeriesDisplayEnum.Hide

    'ds.FitType = C1.Win.C1Chart.FitTypeEnum.Line

    'ds.LineStyle.Pattern = C1.Win.C1Chart.LinePatternEnum.Solid

    Dim i As Integer

    For i = 0 To dv.Table.Rows.Count - 1

    ds.X(i) = dv(i)(0)

    ds.Y(i) = dv(i)(1)

    Next i

    ds.SymbolStyle.Shape = C1.Win.C1Chart.SymbolShapeEnum.None

    'ds.SymbolStyle.Color = Color.Transparent

    ds.X.DataType = GetType(System.DateTime())

    c1Chart.DataSource = dv

    c1Chart.DataBind()

    c1Chart.Width = 600

    c1Chart.Height = 400

    End Sub

     

    Thanks for all the help!! The guys here at work are starting to love the idea of having this on our site reports!

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