Following is not a perfect solution. This is more of a hack to achieve the results
. If you decide to use it, please be cautious with this approach. This may not yield the expected results all the time.
Since SSRS doesn't differentiate two values on the same axes on a line chart, you can do something as shown in the following example. The example uses SSRS 2008 R2
and the query used in the report dataset will work only with SQL Server 2005 or above
.
Step-by-step process:
In an SQL Server database, create a table named dbo.ReportData
using the scripts provided under the SQL Scripts section.
Populate the table with data as shown in screenshot #1. I have used the data provided in the question but also added an identity column to maintain the order.
Create an SSRS report and create a dataset named ReportData with the following query:
SELECT Category + RANK() OVER(PARTITION BY Category ORDER BY Id) * .0001 AS Fraction, Category, Value FROM dbo.ReportData ORDER BY Id
. Refer screenshot #2.
The above given dataset query partitions the rows by the column Category and then assigns a rank within each category based on the column Id. This ranking value is multiplied by .0001 and then value in Category column is added to this fraction. This calculated column almost gives the same value as Category but differs by 1 thousandth of a fraction by keeping the values unique. Refer screenshot #3 for the output of this query.
On the report, place a Chart control of Line type and configure the Chart Data section as shown in screenshot #4. The Fraction column, which is the newly calculated column should be in the Category Groups
section and the Value column should be in the Values
section of the Chart.
Right-click on the X axis and select Horizontal Axis Properties...
Refer screenshot #5.
Configure the Horizontal Axis Properties as shown in screenshot #6. For the Maximum dropdown, click on the Function (fx) button and configure the expression as shown in screenshot #7.
For the data shown in screenshot #1, report execution would yield the results shown in screenshot #8. Similar to the chart provided in the question.
Let's rearrange the rows in the table and also will add few more additional rows as shown in screenshot #9.
For the data shown in screenshot #9, the report dataset query would yield the result shown in screenshot #10 and the report execution would yield the output shown in screenshot #11.
Hope that helps.
SQL Scripts:
CREATE TABLE [dbo].[ReportData](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Category] [int] NOT NULL,
[Value] [int] NOT NULL,
CONSTRAINT [PK_ReportData] PRIMARY KEY CLUSTERED ([Id] ASC)) ON [PRIMARY]
GO
Screenshot #1:
Screenshot #2:
Screenshot #3:
Screenshot #4:
Screenshot #5:
Screenshot #6:
Screenshot #7:
Screenshot #8:
Screenshot #9:
Screenshot #10:
Screenshot #11: