Click here to Skip to main content
12,403,983 members (76,787 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

240K views
14.8K downloads
51 bookmarked
Posted

ASP.NET Server-Side Charting with OWC11

, 9 Jun 2004
ASP.NET Server-Side Charting with OWC11
bin
Interop.MSComctlLib.dll
Interop.OWC11.dll
WebGraphApp_OWC11_Sample.dll
Global.asax
images
WebGraphApp_OWC11_Sample.vbproj.webinfo
WebGraphApp_OWC11_Sample.vsdisco
_private
_vti_cnf
_vti_pvt
access.cnf
deptodoc.btr
doctodep.btr
service.cnf
service.lck
services.cnf
_vti_script
_vti_txt
Imports OWC11

Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents Image1 As System.Web.UI.WebControls.Image
    Protected WithEvents Label1 As System.Web.UI.WebControls.Label
    Protected WithEvents cboCharts As System.Web.UI.WebControls.DropDownList
    Dim Chartspace1 As New OWC11.ChartSpace()

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        GenerateGraphUsingLinearArrays()

        'DeleteFiles(Server.MapPath("."))

    End Sub

    Private Sub GenerateGraphUsingLinearArrays()

        Dim aX() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        Dim aY() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        Dim aY2() = {4, 5, 6, 7, 8, 9, 10, 11, 12, 13}
        Dim aTheta() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        Dim aCategory() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        Dim aHigh() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
        Dim aLow() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

        Dim objChart
        Dim objChartSeries1
        Dim objChartSeries2
        Dim strChartType

        Dim strSavePath As String

        Chartspace1.Clear()

        objChart = Chartspace1.Charts.Add

        objChartSeries1 = Chartspace1.Charts(0).SeriesCollection.Add
        objChartSeries2 = Chartspace1.Charts(0).SeriesCollection.Add

        'Filtering out the combo Type.
        'Combo Type is nothing but different Series in different Types.
        'Like One Series in Bar Type and another Series in Line Type.
        'So for this Combo Type, Series Type will be set.
        If Not cboCharts.SelectedItem.Value < 0 Then
            Chartspace1.Charts(0).Type = cboCharts.SelectedItem.Value
        End If

        strChartType = Left(cboCharts.SelectedItem.Text.ToString, 5)

        Select Case strChartType
            Case "Scatt"
                'Scatter (XY) charts
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y")
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y2")
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimXValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aX)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimXValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aX)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimYValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimYValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY2)
            Case "Polar"
                'Polar charts
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y")
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y2")
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimThetaValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aTheta)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimThetaValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aTheta)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimRValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimRValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY2)
            Case "Bubbl"
                'Bubble charts
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimXValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aX)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimYValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimBubbleValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY2)
            Case "Stock"
                'HLC and OHLC charts, Y=open, Y2=close
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aCategory)
                'Open value only valid for OHLC charts
                If cboCharts.SelectedItem.Text.ToString = "StockOHLC" Then
                    objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimOpenValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY)
                End If
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimCloseValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY2)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimHighValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aHigh)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimLowValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aLow)
            Case "Combo"
                'Combo charts, each dataseries must be given a chart type (only certain combinations allowed)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y")
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y2")
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aCategory)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aCategory)
                objChartSeries1.Type = Chartspace1.Constants.chChartTypeBar3D
                objChartSeries2.Type = Chartspace1.Constants.chChartTypeLine3D
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY2)
            Case Else
                'All other chart types
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y")
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimSeriesNames, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, "Y2")
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aCategory)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimCategories, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aCategory)
                objChartSeries1.SetData(OWC11.ChartDimensionsEnum.chDimValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY)
                objChartSeries2.SetData(OWC11.ChartDimensionsEnum.chDimValues, OWC11.ChartSpecialDataSourcesEnum.chDataLiteral, aY2)
        End Select
        'The Category Axes values can be string literals.

        Chartspace1.Charts(0).HasLegend = True
        Chartspace1.Charts(0).Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom
        Chartspace1.HasChartSpaceTitle = True
        Chartspace1.ChartSpaceTitle.Caption = "ChartSpace Title"
        Chartspace1.ChartSpaceTitle.Font.Bold = True
        Chartspace1.ChartSpaceTitle.Font.Underline = UnderlineStyleEnum.owcUnderlineStyleSingle

        Chartspace1.Charts(0).SeriesCollection(0).Trendlines.Add()

        strSavePath = Server.MapPath(".") & "\Sample.gif"
        Chartspace1.ExportPicture(strSavePath, "gif", 800, 400)

        Image1.ImageUrl = strSavePath

    End Sub

    Private Sub DeleteFiles(ByVal strPath As String)
        Dim di As System.IO.DirectoryInfo
        Dim arri() As System.IO.FileInfo
        Dim f As System.IO.FileInfo
        Dim min As TimeSpan
        di = New System.IO.DirectoryInfo(strPath)
        arri = di.GetFiles("*Sample.gif")
        For Each f In arri
            f.Delete()
        Next
    End Sub

    Private Sub cboCharts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboCharts.SelectedIndexChanged
        GenerateGraphUsingLinearArrays()
    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

ravie gopal
Web Developer
United States United States
Author is an Engineering Graduate majoring in Computer Science. He is currently working as a Programmer Analyst with Cognizant Technology Solutions and prior worked with Keane India Ltd., Offshore of Keane Inc., BOSTON, USA. His Skill Set includes C, C++, VC++, VB(.Net), ASP(.Net), C#, SQL Server, Oracle and SAS. He is currently working on .Net Platform and develops WebForms in ASP.Net.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160721.1 | Last Updated 10 Jun 2004
Article Copyright 2004 by ravie gopal
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid