This topic describes how to use FineReport to connect to an AnalyticDB for MySQL cluster and manage reports.
- You understand the compatibility between FineReport and AnalyticDB for MySQL. For more information, see Compatibility overview.
- MySQL Connector/J is installed.
- FineReport is installed. If this is the first time you are installing FineReport,
you must install a MySQL server such as ApsaraDB RDS for MySQL to import FineReport
metadata. You can use one of the following methods to import data from the MySQL server
- Method 1: Establish the connection in a data-based decision making system. For more information, see [Designer] Connect to a database.
- Method 2: Establish the connection by using the FineReport designer. If you use a MySQL server whose major version is 5.x, see [Platform] Connect to MySQL. If you use a MySQL server whose major version is 8.x, see [Platform] Connect to MySQL.
- For information about how to connect to an AnalyticDB for MySQL cluster over the Internet, see Apply for or release a public endpoint.
Connect to AnalyticDB for MySQL
- Start FineReport. In the top menu bar, choose .
- In the Define Data Connection dialog box, configure the parameters described in the following table.
Parameter Description Database The engine of the database. Select MySQL from the drop-down list. Driver The type of the driver. Select com.mysql.jdbc.Driver from the drop-down list. URL The connection string of the AnalyticDB for MySQL cluster to which you want to connect. The format is
jdbc:mysql://hostname:port. Field description:
hostname: the public or Virtual Private Cloud (VPC) endpoint of the cluster.
port: the port number of the AnalyticDB for MySQL cluster endpoint. The default port number is 3306.
Username The name of the account used to connect to the AnalyticDB for MySQL cluster. You can use one of the following account types:
- Privileged account
- Standard account
Password The password of the account used to connect to the AnalyticDB for MySQL cluster.
- After you configure the preceding parameters, click Test Connection. After the connection passes the test, click OK to connect to the AnalyticDB for MySQL cluster.
Create a table
- Click the Template Dataset tab and then click the + icon in the upper-left corner of the tab.
- Select DB Query from the drop-down list.
- In the DB Query dialog box, set Name to ds1. Select the AnalyticDB for MySQL cluster
from the drop-down list in the upper-left corner. In the left-side list, click the
corresponding table. In the right-side editor, enter the data query statements. In
this example, the
select * from demo_salesstatement is used to query and retrieve all the data in the demo_sales table, as shown in the following figure.
- Obtain the dataset that consists of the results of an aggregate query. For example,
you can create a dataset named
ds2and then query and retrieve the total sales of each store by using the following query statement:
SELECT <Store name>, SUM(Revenue) AS <Total sales volume> FROM demo_sales GROUP BY <Store name>.
- Click OK. The retrieved data is displayed in the dataset management panel.
In this example, a report is created. It contains tables and column charts that display the largest sales volumes and total sales volumes sorted by product type, payment type, and contract type. The following figure shows the report.
- Download the demo table named demo_contract.
- Create a table in the AnalyticDB for MySQL cluster.
- Use a column whose values are evenly distributed as the distribution key, and a column that contains time data as the partition key. For more information, see Schema design.
- The contract_id column is used as the partition key. This is because the values in
the contract_id column are randomly distributed. The following statement is used to
create the table:
Create Table `demo_contract` ( `contract_id` varchar, `customer_id` varchar, `contract_type` varchar, `amount` bigint, `payment_type` varchar, `register_time` date, `purchase_amount` int, `create_time` timestamp, `product_type` smallint, `paid` tinyint, primary key (`contract_id`) ) DISTRIBUTE BY HASH(`contract_id`) INDEX_ALL='Y' STORAGE_POLICY='COLD'
- After the table is created, use Kettle to import data from the XLSX file to AnalyticDB for MySQL.
- For information about how to use Kettle, see Use Kettle to synchronize local data to AnalyticDB for MySQL.
- After the data is imported, execute the
SELECT count(*) FROM demo_contractstatement. 668 entries are returned.
- Import data from the d1 and d2 tables to FineReport. The data is sorted by payment
type and contract type. The maximum sales volume of each payment type and the total
sales volume are calculated. Two tables named d1 and d2 are imported.
- Execute the following statement to categorize the data in the d1 table by product
type, contract type, and payment type and obtain the maximum sales volume under each
select product_type, payment_type, contract_type, max(purchase_amount) as max_amount from demo_contract group by product_type, payment_type, contract_type having max_amount>0
- Categorize the data in the d2 table by product type and contract type, and calculate the total sales volume of all payment types, as shown in the following figures.
- Execute the following statement to categorize the data in the d1 table by product type, contract type, and payment type and obtain the maximum sales volume under each category:
- Perform the following operations to design the table:
- Title: Merge the A1 to D2 cells and enter the following title in the merged cell: Contract Sales Overview. Set the font size to 15 and make the title bold and centered.
- Angled lines: Use angled lines to separate the category names in the upper-left cell. Merge the A3 and B3 cells, right-click the merged cell, and then choose Slope Line dialog box, enter the following content in the field: Payment Type | Contract Type | Product Type. You can add spaces to adjust the positions of the text. . In the
- Add formulas to cells.
- Drag the columns that have an uneven distribution of values to the corresponding cells.
- Click the C5 cell, and click the Insert Formula icon in the shortcut bar above the parameter pane. In the Formula Definition dialog box, enter the following formula in the editor: SUM(C4). This sums up the values in the C4 cell. The C5 cell is used to calculate the total sales volume of each product.
- Repeat the preceding operations to add the SUM(D4) formula to the D5 cell. The D5 cell is used to calculate the total sales volume of all products.
- Set the expansion directions of cells.
- Click the C3 cell. In the panel, click Cell Attributes. In the Cell Attributes dialog box, click the Expand tab. On the Expand tab, set Expand Direction to H in the Basic section. The product type data expands in an horizontal manner.
- Repeat the preceding operations to set Expansion Direction of C4 to No Expansion. This is because the sales volumes in the A4, B4, and C3 cells are unique. The expansion direction of the C5 and D5 cells must also be set to No Expansion.
- When data of various datasets is presented in the same report, you must associate
the datasets by adding data filter conditions. The following section describes how
to associate multiple datasets:
The data of the report is stored in the ds1 and ds2 datasets. Both of the datasets have the product type and contract type fields. Therefore, the two fields are used to associate the two datasets. Double-click the D4 cell. In the Data Column dialog box, click the Filter tab. On the Filter tab, add a common condition to the D4 cell to associate the product type and contract type fields of the ds2 and ds1 datasets.
- Design the chart.
- Merge the A7 to D15 cells. In the top menu bar, choose Column Chart in the Chart Type list, select Column Chart in the right-side list, and then click OK. . Click
- Click the chart. In the panel, click Cell Element. In the dialog box that appears, click the Data tab. Set Data Source to Cell Data, Category to =B4, Series to =C3, and Value to =C4.
Note You must add an equal sign (=) before a cell number when you set the Category, Series, and Value parameters. Otherwise, the cell number is processed as a string.
- If you want to preview the report, you must save it first. Click Save in the top shortcut bar. Then, click Preview and select Pagination Preview from the drop-down list. The report is opened in your web browser.
For information about the differences between FineReport and FineBI, see Differences between FineReport and FineBI.
FineReport and FineBI are similar in some operations. For more information about FineBI, see FineBI.
For information about how to get started with FineReport, see Designer.
For information about how to design a FineReport report, see Learning path.