Here is a simple ASP.NET 2.0 app that demonstrates the use of OWC11 to create a pie chart from a sql server 2000 database using an ObjectdataSource. </o> </o> You?ll have to create a sql query and connection that will return the fields the business object is looking for to actually run it.</o> </o> I?ve spent many hours and not an insignificant quantity of alcohol fussing with this and related syntax ? and the discountASP support folks have been very helpful - so thought I?d share this on the forum in the event anyone else might be experiencing similar struggles.</o> </o> Here we go -</o> </o> Create a new web project (file system) : owc_test</o> </o> Add new asp.net folder: bin</o> </o> Add OWC11 reference: </o> Select website from menu.</o> Select Add_Reference</o> Click the Com tab</o> Choose Microsoft Office Web Components 11.0</o> Click OK</o> This will add the Interop.OWC11.dll to the bid folder (along with three other dll?s which you can delete if you wish).</o> </o> Add new asp.net folder: app_code</o> </o> In the App_Code folder add: owc_data.vb</o> Code as follows:</o> </o> Imports Microsoft.VisualBasic</o> Imports System</o> Imports System.Configuration</o> Imports System.Data</o> Imports System.Data.SqlClient</o> Imports System.Collections.Generic</o> Imports System.Web.UI</o> Imports System.Web.UI.WebControls</o> Imports OWC11</o> </o> Namespace BusinessLogicLayer</o> </o> Public Class owc_data</o> </o> Public ChartItems As DataSet</o> Public ChartxArr() As String</o> Public ChartyArr() As String</o> Public aSeries() As String</o> Public aColors() As String</o> Public aAxis() As String</o> </o> Public Function GetChartDataplpie(ByVal id As Integer)</o> Dim dsn As String = ConfigurationManager.ConnectionStrings("ConnStr").ConnectionString</o> Dim myConnection As SqlConnection = New SqlConnection(dsn)</o> Dim myCommand As SqlCommand = New SqlCommand("your_stored_proc", myConnection)</o> Dim parameteridx As SqlParameter = New SqlParameter("@your_param", SqlDbType.Int)</o> parameteridx.Value = id</o> myCommand.Parameters.Add(parameteridx)</o> Dim sda As New SqlDataAdapter(myCommand)</o> Dim PriceList As New DataSet</o> myCommand.CommandType = CommandType.StoredProcedure</o> myConnection.Open()</o> sda.Fill(PriceList)</o> Dim rcnt As Integer = PriceList.Tables(0).Rows.Count()</o> ReDim ChartxArr(rcnt - 1)</o> ReDim ChartyArr(rcnt - 1)</o> Dim row As DataRow</o> Dim cnt As Integer = 0</o> For Each row In PriceList.Tables(0).Rows</o> ChartxArr(cnt) = row("acct").ToString()</o> ChartyArr(cnt) = row("amt").ToString()</o> cnt = cnt + 1</o> Next row</o> Return PriceList</o> End Function</o> </o> <CLSCompliantAttribute(False)> _</o> Public Function Chartplpie(ByVal chartCatArr() As String, ByVal chartVal1Arr() As String) As OWC11.ChartSpaceClass</o> </o> Dim chartCategoriesArr As String() = chartCatArr</o> Dim chartValues1Arr As String() = chartVal1Arr</o> </o> Dim chartCategoriesStr As String = String.Join(ControlChars.Tab, chartCategoriesArr)</o> Dim chartValues1Str As String = String.Join(ControlChars.Tab, chartValues1Arr)</o> </o> Dim oChartSpace As OWC11.ChartSpaceClass = New OWC11.ChartSpaceClass</o> </o> ReDim aColors(3)</o> aColors(0) = "Brown"</o> aColors(1) = "Blue"</o> aColors(2) = "red"</o> </o> oChartSpace.Border.Color = "white"</o> oChartSpace.Charts.Add(0)</o> oChartSpace.Charts(0).HasTitle = False</o> oChartSpace.Charts(0).PlotArea.Interior.Color = "cornsilk"</o> oChartSpace.Charts(0).HasLegend = False</o> oChartSpace.Charts(0).SeriesCollection.Add(0)</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection.Add()</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection(0).HasCategoryName = True</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection(0).HasValue = False</o> oChartSpace.Charts(0).SeriesCollection(0).Caption = String.Empty</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection(0).Font.Name = "verdana"</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection(0).Font.Size = 10</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection(0).Font.Bold = True</o> oChartSpace.Charts(0).SeriesCollection(0).DataLabelsCollection(0).Font.Color = "red"</o> oChartSpace.Charts(0).SeriesCollection(0).SetData(OWC11.ChartDimensionsEnum.chDimCategories, _</o> Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartCategoriesStr)</o> oChartSpace.Charts(0).SeriesCollection(0).SetData(OWC11.ChartDimensionsEnum.chDimValues, _</o> Convert.ToInt32(OWC11.ChartSpecialDataSourcesEnum.chDataLiteral), chartValues1Str)</o> oChartSpace.Charts(0).SeriesCollection(0).Type = oChartSpace.Constants.chChartTypePieExploded3D</o> oChartSpace.Charts(0).Rotation = 160</o> </o> Return oChartSpace</o> </o> End Function</o> </o> End Class</o> </o> End Namespace</o> </o> </o> </o> Change web_config to: </o> </o> </o> <configuration></o> </o> <connectionStrings></o> <add name="ConnStr" connectionString="Data Source=localhost;Initial Catalog=your_database;Persist Security Info=True; User ID=your_user;Password=your_pw" providerName="System.Data.SqlClient"/></o> </connectionStrings></o> </o> <system.web></o> </o> <authentication mode="Forms"></o> </authentication></o> </o> <authorization></o> <allow users="*"/></o> </authorization></o> </o> <trace enabled="false"/></o> </o> </system.web></o> </o> </configuration></o> </o> </o> Create an new web page in the root: owc_chart.aspx</o> Code as follows:</o> </o> <%@ Page Language="VB" AutoEventWireup="false" CodeFile="owc_chart.aspx.vb" Inherits="owc_chart" %></o> </o> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></o> </o> <html xmlns="http://www.w3.org/1999/xhtml" ></o> <head id="Head1" runat="server"></o> <title><st1:Street w:st="on"><st1:address w:st="on">Chart PL</title></o> </head></o> </o> <form id="form1" runat="server"></o> <div></o> </o> </div></o> </form></o> </body></o> </html></o> </o> </o> Page code-behind as follows:</o> </o> Imports BusinessLogicLayer</o> Imports OWC11</o> </o> Partial Class owc_chart</o> Inherits System.Web.UI.Page</o> </o> Protected WithEvents ChartSpace1 As OWC11.ChartSpace</o> </o> Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As System.EventArgs) Handles MyBase.Load</o> </o> Dim pl As owc_data = New owc_data</o> Response.Buffer = True</o> Response.ContentType = "image/gif"</o> pl.GetChartDataplpie(32) '</o> ChartSpace1 = pl.Chartplpie(pl.ChartxArr, pl.ChartyArr)</o> Response.BinaryWrite(ChartSpace1.GetPicture("gif", 400, 400))</o> Response.End()</o> </o> End Sub</o> </o> End Class</o> </o> </o> That?s about it ? run the app and you should create a 3-d pie chart (2-d on discountASP - must be the com ver.).</o> </o> Create your remote database and FTP the web code to discountASP as is and it should run fine.</o> </o> Do you best to enjoy the day ? life is short. </o> </o>
Very cool.. not many people have successfully used OWC with InterOp. It bombed on me a few times... so i gave up!! Bruce DiscountASP.NET www.DiscountASP.NET