Home All Groups Group Topic Archive Search About

OWC11 (connect Spreadsheet + Chart)

Author
30 Jun 2005 8:55 AM
Pieter
Hi

In my application I've got an AxSpreadsheet with data.
I want to draw a chart from the data in the spreadsheet.

I am having trouble "connecting" the spreadsheet to the chart.
I found quite a few examples on the net on doing this but all of these
examples says:
ChartSpace1.DataSource = Spreadsheet1

This results in a "Option stric on disallows implicit conversion....."
(I don't want to turn strict off)

When I typecast to
ChartSpace1.DataSource = CType(Spreadsheet1, msdatasrc.DataSource)

and run the code,  it results in "Specified cast is not valid"

Any ideas? ( I am using VB.NET)

Thanks in advance

Author
1 Jul 2005 12:01 AM
Alvin Bruney [MVP - ASP.NET]
This isn't correct. The correct code and explanation, as taken from the
black book p.137, is listed below.


Loading from a datasource




Finally, the chart is capable of binding to a datasource directly. This

datasource may not necessarily be a database but it can actually be a pivot

listing or a spreadsheet component. In fact, the chart can bind to any
container implementing the IDataSource interface. Binding a chart to a
spreadsheet is a hidden gem because it provides the ability to chart data in
real time. Let us examine one possibility.




Code-listing 4.11 Sample code to bind to a spreadsheet

C# snippet




ChartSpace1.DataSource =
Spreadsheet1.SetData(ChartDimensionsEnum.chDimCategories, (int)

ChartSpecialDataSourcesEnum.chDataBound, "A1:A40");




SpreadSheet1.SetData(ChartDimensionsEnum.chDimValues, (int)

ChartSpecialDataSourcesEnum.chDataBound, "B1:B40");




VB.NET snippet




ChartSpace1.DataSource =
Spreadsheet1.SetData(ChartDimensionsEnum.chDimCategories, CType

(ChartSpecialDataSourcesEnum.chDataBound, "A1:A40", Integer))




SpreadSheet1.SetData(ChartDimensionsEnum.chDimValues, CType

(ChartSpecialDataSourcesEnum.chDataBound, "B1:B40", Integer))

--
Regards,
Alvin Bruney - ASP.NET MVP


[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
Show quoteHide quote
"Pieter" <pauc***@webmail.co.za> wrote in message
news:da0c29$2vo$1@ctb-nnrp2.saix.net...
> Hi
>
> In my application I've got an AxSpreadsheet with data.
> I want to draw a chart from the data in the spreadsheet.
>
> I am having trouble "connecting" the spreadsheet to the chart.
> I found quite a few examples on the net on doing this but all of these
> examples says:
> ChartSpace1.DataSource = Spreadsheet1
>
> This results in a "Option stric on disallows implicit conversion....."
> (I don't want to turn strict off)
>
> When I typecast to
> ChartSpace1.DataSource = CType(Spreadsheet1, msdatasrc.DataSource)
>
> and run the code,  it results in "Specified cast is not valid"
>
> Any ideas? ( I am using VB.NET)
>
> Thanks in advance
>
>