SSRS折线图在一个折线图中连接两个值

时间:2016-02-22 15:27:06

标签: reporting-services ssrs-2008 ssrs-2008-r2

我的折线图包含3个值(上一年实际,预测和当前年度实际)和类别组(月 - 年前:2016年1月)。我可以将3个值放在折线图中,但我很难绘制一条连续线(带标记)"首先,我想绘制当前年度实际值,并在上个月,例如,2016年2月,预测的图表行将显示。我可以在MSExcel中执行此操作,左边的行是实际的,黄色的突出显示是预测,但我无法在SSRS中执行此操作。请指教。 LineChart

1 个答案:

答案 0 :(得分:0)

在您的选择查询中合并您的数据。您可以使用UNION语句,如下例所示。

SELECT actual_sales AS 'sales'
    , calendar_day AS 'calendar_day'
    , 'actual' AS 'sales_type'
FROM actual_sales_data
UNION
SELECT projected_sales AS 'sales'
    , calendar_day AS 'calendar_day'
    , 'projected' AS 'sales_type'
FROM projected_sales_data

然后,您可以在连续线中绘制两种类型的销售(实际和预计),因为它将是一个数据集。

以下是您可以使用示例查询的一些示例数据:

DECLARE @actual_sales_data TABLE (actual_sales int, calendar_day DATE)
DECLARE @projected_sales_data TABLE (projected_sales int, calendar_day DATE)

INSERT INTO @actual_sales_data
SELECT 100, '1/1/2016'
UNION
SELECT 200, '1/2/2016'
UNION
SELECT 150, '1/3/2016'
UNION
SELECT 180, '1/4/2016'
UNION
SELECT 210, '1/5/2016'
UNION
SELECT 230, '1/6/2016'
UNION
SELECT 200, '1/7/2016'
UNION
SELECT 220, '1/8/2016'


INSERT INTO @projected_sales_data
SELECT 220, '1/8/2016' -- This data point matches the last actual sales number so that SSRS will draw a continuous line
UNION
SELECT 250, '1/9/2016'
UNION
SELECT 220, '1/10/2016'
UNION
SELECT 180, '1/11/2016'
UNION
SELECT 250, '1/12/2016'
UNION
SELECT 210, '1/13/2016'
UNION
SELECT 270, '1/14/2016'
UNION
SELECT 200, '1/15/2016'
UNION
SELECT 290, '1/16/2016'

SELECT actual_sales AS 'sales'
    , calendar_day AS 'calendar_day'
    , 'actual' AS 'sales_type'
FROM @actual_sales_data
UNION
SELECT projected_sales AS 'sales'
    , calendar_day AS 'calendar_day'
    , 'projected' AS 'sales_type'
FROM @projected_sales_data
相关问题