Fanruan FineReport draws funnel chart

July 1st Party Day, happy birthday to the party!
The summer is hot, and I am at home on weekends. I remembered that when I used Fanruan to display the page, I used a funnel chart and recorded it for easy viewing.
Taking the change of order sales as an example, it is divided into five stages, the number of product viewers, the number of people who click on the product, the number of people who create an order, the number of people who add to the shopping cart and the task of paying for the order, etc., to achieve the effect. The display effect is roughly as shown in the figure below.
insert image description here

The first step, construct the basic list

Create a new data set, assemble SQL according to five stages, that is, connect through union and then group by to achieve statistics. The query SQL is as follows, for reference only, and can be adjusted according to specific businesses.

select 
data_type,
sum(aa.pvNum) as pvNum,
sum(aa.clickNum) as clickNum,
sum(aa.createNum) as createNum,
sum(aa.cartNum) as cartNum,
sum(aa.payNum) as payNum
from (
SELECT 
        '商品浏览人数' AS 'data_type',
         COUNT(*) AS pvNum,
				0 AS clickNum,
        0 AS createNum,
        0 AS cartNum,
				0 AS payNum
    FROM
        tb_order
    WHERE
        1 = 1 
        AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
        AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
	UNION ALL 
		SELECT 
        '点击商品人数' AS 'data_type',
				0 AS pvNum,
        COUNT(*) AS clickNum,
				0 AS createNum,
        0 AS cartNum,
				0 AS payNum
    FROM
			tb_order
    WHERE
        1 = 1 
		and order_status IN ('CO','OP','FN')
        AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
        AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
	UNION ALL 
		SELECT 
        '创建订单人数' AS 'data_type',
				0 AS pvNum,
        0 AS clickNum,
        COUNT(*) AS createNum,
				0 AS cartNum,
				0 AS payNum
    FROM
         tb_order
    WHERE
        1 = 1 
	and order_status = 'CO'
	AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
	AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
	UNION ALL 
	SELECT 
        '加入购物车人数' AS 'data_type',
				0 AS pvNum,
        0 AS clickNum,
        0 AS createNum,
        COUNT(*) AS cartNum,
				0 AS payNum
    FROM
         tb_order
    WHERE
        1 = 1 
	and order_status = 'CA'
	AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
	AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
UNION ALL 
	SELECT 
        '支付订单人数' AS 'data_type',
				0 AS pvNum,
        0 AS clickNum,
        0 AS createNum,
        0 AS cartNum,
        COUNT(*) AS payNum
    FROM
         tb_order
    WHERE
        1 = 1 
	and order_status = 'OP'
	AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
	AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
) aa

Draw the list, corresponding to the field binding, the effect is shown in the figure below.
insert image description here
The preview effect in the browser is as follows.
insert image description here

The second step is to draw a funnel diagram

In the cell below the list, click the property list, select Insert Element -insert chart, select the typeFunnel Chart (New Feature), the operation is shown in the figure below.
insert image description here
To construct a data source, similarly, the five stages should be spliced ​​separately, and the display value and the corresponding display name should be separated, that iskey-valuesform, pay attention to add a sort field.

SELECT 
    data_type, num
FROM
    (SELECT 
        '商品浏览人数' AS 'data_type',
            COUNT(*) AS num,
            1 AS ordSeq
    FROM
        tb_order
    WHERE
        1 = 1 
        AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
        AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
	UNION ALL 
		SELECT 
        '点击商品人数' AS 'data_type',
            COUNT(*) AS num,
            2 AS ordSeq
    FROM
			tb_order
    WHERE
        1 = 1 
        and order_status IN ('CO','OP','FN')
        AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
        AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
	UNION ALL 
		SELECT 
        '创建订单人数' AS 'data_type',
            COUNT(*) AS num,
            3 AS ordSeq
    FROM
         tb_order
    WHERE
        1 = 1 
        and order_status = 'CO'
	AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
	AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
	UNION ALL 
	SELECT 
        '加入购物车人数' AS 'data_type',
            COUNT(*) AS num,
            4 AS ordSeq
    FROM
         tb_order
    WHERE
        1 = 1 
      and order_status = 'CA'
	AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
	AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
UNION ALL 
	SELECT 
        '支付订单人数' AS 'data_type',
            COUNT(*) AS num,
            5 AS ordSeq
    FROM
         tb_order
    WHERE
        1 = 1 
     and order_status = 'OP'
	AND DATE_FORMAT(created_time, '%Y-%m-%d') >= DATE_ADD('${beginDate}', INTERVAL 1 DAY)
	AND DATE_FORMAT(created_time, '%Y-%m-%d') <= DATE_ADD('${endDate}', INTERVAL 1 DAY)
    ) main
ORDER BY ordSeq asc
;

In the edit bar - data , select the data set data as the data source, that is, the newly created one in the previous step, selectuse field value, specify the series name and value, the effect is as follows.
insert image description here
In the formula bar - style , you can set the funnel charttitle, legend and other information, the effect is shown in the figure below.
insert image description here
Zoom in on the range of the graph, that is, after the selected area,Merge Cells,As shown below.
insert image description here
On the Legend tab, check thelegend visible, and the preview effect in the browser is shown in the figure below.
insert image description here
For example, you can use tags, in the edit bar - format , under tags - tags,use tags.
insert image description here
The display effect in the browser is shown in the figure below.
insert image description here
The above is the process of adding the funnel chart. Fanruan has many attributes, you can debug and check the effect, good luck!

exception handling

[1] The result shows garbled characters, such as? ? ? ?
Solution :
Specify the encoding method as utf8 after the database connection
insert image description here

?useUnicode=true&characterEncoding=utf8

Guess you like

Origin blog.csdn.net/u012190388/article/details/131490967