Working with Charts
Contents[ Hide ]
Aspose.Cells Report template supports Microsoft Excel charts. Each time you execute a report, the chart is populated with the most recent data.
To add a chart to report template:
- First, create the dataset that will be the data source for the chart. Below, we use the AdventureWorks sample database that ships with SQL Server Reporting Services 2005 and create a dataset named Sales. This SQL defines the dataset:
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 Data Sources 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 instructions in Creating Tabular Report. The report we’ve created for this example is below. The table is the chart’s data source.
- In Microsoft Excel, click the Insert menu and select Chart.
- Click Next.
- Click the Series tab.
- Click Add.
- In the dialog box, set the value of Series1 (Quarter series) to the table’s first data field. In the sample, that 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 will be replaced with the table data’s real row index at rendering time. Set the category(X) axis labels to “=CompanySales!$C$3:$C$3”.
- Click Add to add another series. In the sample, we’ve added the sales series.
- Set the value of Series2 (Sales series) to the table’s second data field. 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 will be replaced with the table data’s real row index at rendering time.
- Click Next to continue.
- In the dialog box, set the chart title and category(X) axis.
- Click Finish to complete the work.
The template looks like the below.
- Save the report and publish it to Report Server.
- Export the report from Report Server. The result is as below.