Aspose.Cells Report template supports MS Excel charts. Each time you execute your report, the chart will be populated with the most recent data.
To add a chart to report template, follow the steps below:
- Create a dataset as the data source for the Chart first.
In the sample we use the “AdventureWorks” sample database that ships with SQL Server Reporting Services 2005 and create a dataset named “Sales”.
The sql of the dataset is as under:
SELECT DATEPART(yy,SOH.OrderDate) 'Year',
'Q'+DATENAME(qq,SOH.OrderDate) 'Quarter',
SUM(SOD.UnitPrice*SOD.OrderQty) 'Sales'
FROMAdventureWorks.Sales.SalesOrderDetail SOD,
AdventureWorks.Sales.SalesOrderHeader SOH
WHERE SOH.SalesOrderID = SOD.SalesOrderID
AND ((DATEPART(yy,SOH.OrderDate)=2002))
GROUP BY DATEPART(yy,SOH.OrderDate), 'Q'+DATENAME(qq,SOH.OrderDate)
Please refer to Section “DataSources and Queries” to learn more about how to create a data source and dataset in Aspose.Cells.Report.Designer.
- Create a tabular report according to the instruction described in Section “Creating Tabular Report” as shown in the following. The table will be the data source for Chart.
- Select Insert->Chart from MS Excel Menu and click Next button.
- Click Series Tab.
- Click Add button
- In the dialog box, set the Values of Series1 (Quarter Series) to the first data field of the table. In the sample it is “CompanySales!$C$3:$C$3”. The first $C$3 is the first row index of “Quarter” and the second $C$3 is a placeholder for last row index of “Quarter” and it will be replaced with the real row index of table data at rendering time. Set Category(X) axis Labels to “=CompanySales!$C$3:$C$3”.
- Click add button to add another Series i.e., Sales Series. Set the Values of Series2 (Sales Series) to the second data field of the table. In the sample it is “CompanySales!$D$3:$D$3”. The first $D$3 is the first row index of “Sales” and the second $D$3 is a placeholder for last row index of “Sales” and it will be replaced with the real row index of table data at rendering time. Click Next button to continue.
- In the dialog box, set Chart title and Category(X) axis. Click Finish button to complete the work.
- The template looks like:
- Save the report and publish it to Report Server.
- Export the report from Report Server, the result is shown in the following.