Groups | Blog | Home
all groups > sql server reporting services > july 2004 >

sql server reporting services : Chart problem "X-axis" and "Chart properties/Data/Values"


Paco
7/17/2004 4:27:02 AM
I have two problems with the barchart I made. I made the barchart with data that
I could not read immediately from the Database. The requiered data has to be
calculated by reading data from the database and using a function which I
placed in the "Code" window.
The bar chart I made calculates how many employees are working during a period.
One day is displayed as 24 bars, one bar for every hour.

If e.g. an employee works from 7:30 till 16:30, the barchart shows from the hour
bar number 7 till number 16 one employee working. On the (vertical) Y-axis you can
see the number of employees and the (horizontal) x-axis should display the hours
starting by 0 till 23.

The first problem is that the x-axis can not display anything. This has to do with
the fact that I am not using category groups. I this situation it seems to me that I can not use the category groups because it has no use at all . I made for every hour bar a value in the "Chart properties" window under the "Data" tab. So I made 24 values which I labeled from 0 till 23. The point labels are also from 0 till 23 so I can diplay that on the chart. Otherwise the values of the bars can not be read because the x-axis does not show them.

I used the following expression for the bar 7:
_____________________________________
=Sum(iif(code.WorkingTime(7,Fields!TimeStart.Value, Fields!TimeFinish.Value) ,1,0))
_____________________________________

For the other bars the number 7 is being adjusted to the according hour.
The TimeStart and TimeFinish are "Dates" in the database where I can extract
the necessary information.

I used the following function in the "Code" window to extraxt the working time of an employee.
___________________________________________
Public Function WorkingTime(ByVal valHour As Integer, ByVal valTimeStart As Date, ByVal valTimeFinish As Date) As Boolean
Dim StartHour, EndHour, EndMinutes
StartHour = DatePart(DateInterval.Hour, valTimeStart)
EndHour = DatePart(DateInterval.Hour, valTimeFinish)
EndMinutes = DatePart(DateInterval.Minute, valTimeFinish)

If (StartHour < (valhour + 1)) And _
((EndHour > valhour) or _
(Endhour = valHour And EndMinutes <> 0)) Then
Return True
End If
End Function
_______________________________________________

Everything is working but I am not satisfied with two issues and I like to know if
there are solutions for it. My quesions are:
1. How can I display on the horizontal x-axis the hours from 0 to 23 in the specific
situation I explained or in a way that the same goal is being achieved?
2. How can i make the code easier to mantain? Now I have to fill in for
every hour the expression, that is 24 times. Is there a simpeler way?
I ask this because I probably have to expand this chart, the client
like to see the information on a 15 minutes basis. This means I will
have to fill in (24 X 4 =) 96 times the same expression.

Thanks in advance for any help.

Robert Bruckner [MSFT]
7/18/2004 4:28:34 PM
These are the alternatives you have:

(1) In order to have the X-axis show values from 0 to 23 you would need use
"static category groups". This is supported in the RDL and on the report
server, however currently not in the report design tool. Therefore you would
need to manually convert the 24 "values" (which are actually static series
groups) into static category groups.

(2) Write a stored procedure that converts the current data storage
structure from 1 row containing TimeStart, TimeFinish into one row per e.g.
work hour or work quarter. Then you could simply create a chart based on the
stored procedure dataset with a category grouping =Fields!WorkHour, no
series grouping, and a value of =Count(Fields!EmployeeID.Value). For the
X-axis you would turn on "Numeric or time-scale values" and set a minimum of
0 and a maximum of 24.

--
This posting is provided "AS IS" with no warranties, and confers no rights.



[quoted text, click to view]
me that I can not use the category groups because it has no use at all . I
made for every hour bar a value in the "Chart properties" window under the
"Data" tab. So I made 24 values which I labeled from 0 till 23. The point
labels are also from 0 till 23 so I can diplay that on the chart. Otherwise
the values of the bars can not be read because the x-axis does not show
them.
[quoted text, click to view]

Paco
7/19/2004 2:30:02 AM
I tried alternative (1). I did not succeed after making the convert. I get the following 2 error messages:

C:\......\filename.rdl The chart ‘chart1’ contains a different number of ChartSeries elements than the number of StaticSeries elements. If the chart contains no StaticSeries, it must contain one ChartSeries.

C:\......\filename.rdl The chart ‘chart1’ contains a different number of DataPoints per ChartSeries element than the number of StaticCategory elements. If the chart contains no StaticCategory, it must contain one DataPoint per ChartSeries.

This is the change I made in the rdl:
<CategoryGroupings>
<CategoryGrouping>
<StaticCategories>
<StaticMember>
<Label>0</Label>
</StaticMember>

e.t.c. till 23

<StaticMember>
<Label>23</Label>
</StaticMember>
</StaticCategories>
</CategoryGrouping>
</CategoryGroupings>

I think I also have to change the following code but I do not know what the changes have to be:

<ChartData>
<ChartSeries>
<DataPoints>
<DataPoint>
<DataValues>
<DataValue>
<Value>=Sum(iif(code.Inzet(0,Fields!TijdVan.Value, Fields! TijdTot.Value) ,1,0))</Value>
</DataValue>
</DataValues>
<DataLabel>
<Value>0</Value>
<Visible>true</Visible>
</DataLabel>
<Style>
<BackgroundColor>Green</BackgroundColor>
</Style>
<Marker>
<Size>6pt</Size>
</Marker>
</DataPoint>
</DataPoints>
</ChartSeries>

till 23

</ChartData>

At this moment the code is not working with the new changes I made. Is it correct that I have to change the previous code? If so, how? Is there something else a matter why it is not working?

Paco



[quoted text, click to view]
Robert Bruckner [MSFT]
7/19/2004 1:08:43 PM
The CategoryGroupings section of the RDL file seems correct.
However, you also need to change the structure of the ChartData section.
Rather than 1 Datapoint per ChartSeries element and 24 ChartSeries elements
in the entire file (i.e. 24 static series), you need to have just 1
ChartSeries element which contains 1 DataPoints element with 24 DataPoint
elements (i.e. 24 static categories).

--
This posting is provided "AS IS" with no warranties, and confers no rights.



[quoted text, click to view]
ChartSeries elements than the number of StaticSeries elements. If the chart
contains no StaticSeries, it must contain one ChartSeries.
[quoted text, click to view]
DataPoints per ChartSeries element than the number of StaticCategory
elements. If the chart contains no StaticCategory, it must contain one
DataPoint per ChartSeries.
[quoted text, click to view]
correct that I have to change the previous code? If so, how? Is there
something else a matter why it is not working?
[quoted text, click to view]
achieved?
Paco
7/20/2004 1:45:01 AM
I changed the code as you described and it is working fine. However, the expression has to be in every dataopint in the RDL file. I tried to change and test what happens if I change the code going to "Chart properties/data/values/".
There is only the first expression and if I change it the whole chart does not work anymore. It seems to me I can not do anything in that section because the chart will not work. If I could make some changes I would trie to use a code with a loop to get the 24 "hour bars".

How can I use the expression one time? Is it e.g. possible to make a function, in the code window or an assembly, with a loop so the code is written 24 times to the RDL file by calling that function in the RDL file? This way I only have to make changes in the function. Or is there an other possiblity?

[quoted text, click to view]
Robert Bruckner [MSFT]
7/20/2004 7:47:21 AM
If you use "static categories", then as I mentioned in my first posting, you
can no longer modify the report in the report designer because it does _not_
support it - only the server supports it right now. If you load it in report
designer and modify any property it will destroy the original changes. Just
upload the modified RDL on the server and it will work.
Also, as indicated in the other post, you will need 24 static categories and
therefore have 24 datapoints (1 datapoint per static category). The only
thing you gained by approach (1) is to have control over the X-axis.

If you just want to have 1 datapoint expression, then you have to use
approach (2). As described earlier, you will need to write a stored
procedure and change the structure of the dataset. Then you will then just
have 1 datapoint defined with =Count(Fields!EmployeeID.Value) and 1 dynamic
category grouping =Fields!WorkHour.Value, which will automatically group the
data per workhour.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]
expression has to be in every dataopint in the RDL file. I tried to change
and test what happens if I change the code going to "Chart
properties/data/values/".
[quoted text, click to view]
not work anymore. It seems to me I can not do anything in that section
because the chart will not work. If I could make some changes I would trie
to use a code with a loop to get the 24 "hour bars".
[quoted text, click to view]
function, in the code window or an assembly, with a loop so the code is
written 24 times to the RDL file by calling that function in the RDL file?
This way I only have to make changes in the function. Or is there an other
possiblity?
[quoted text, click to view]
Paco
7/21/2004 4:02:02 PM
I succeeded with the stored procedure. I also had to make a "user definded function" and it is all working fine now.

There is one problem. Before I had the hour bars in two different colors (green, red), the first bar was green and the second red etc. In this way you can see them better.
They way I made it now they can have only one color (also a gradient). Is it possible to give the bars different colors like e.g the first bar is green and the second is red etc? The bars are then better to be differentiated. Also if it is printed (black & white) you can see the bars better by having different colors (green, red = light, dark).

I hope someone can help me with this one.

[quoted text, click to view]
Robert Bruckner [MSFT]
7/21/2004 7:21:48 PM
If you use SP1, you have control over the datapoint colors.

Assuming you have a category grouping like =Fields!WorkHour.Value and no
dynamic series grouping, you can write an expression for the datapoint color
()
=Choose(CInt(Fields!WorkHour.Value), "Green", "Blue", "Yellow", .......)

MSDN docs for Choose:
http://msdn.microsoft.com/library/en-us/vblr7/html/vafctchoose.asp

Alternatively, you can calculate some RGB values based on the WorkHour
value. Note: color expressions have to evaluate to strings, therefore you
have to convert the RGB value into a string like this:
=String.Format("#{0:x6}", RGB(CInt(Fields!WorkHour.Value) * 5, 1, 96))

MSDN docs for RGB:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctrgb.asp

Note: if you use a dynamic series grouping in the chart, you have to use an
aggregate function using the name of the dynamic series grouping as scope
when refering to WorkHour. Examples:
=Choose(CInt(First(Fields!WorkHour.Value, "SeriesGroupName")), "Green",
"Blue", "Yellow", .......)
=String.Format("#{0:x6}", RGB(CInt(First(Fields!WorkHour.Value,
"SeriesGroupName")) * 5, 1, 96))

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]
(green, red), the first bar was green and the second red etc. In this way
you can see them better.
[quoted text, click to view]
it possible to give the bars different colors like e.g the first bar is
green and the second is red etc? The bars are then better to be
differentiated. Also if it is printed (black & white) you can see the bars
better by having different colors (green, red = light, dark).
[quoted text, click to view]
Paco
7/24/2004 1:45:15 PM
I made my Barchart and it is working OK. There is however a difference in display when having different values that makes up the barchart and a barchart that is made up by a Category Group.
If I use the values, the barcharts are connected to each other and therefore they are thicker and better displayed compared to a barchart made up by a Category group. The bars made up by a Category group have a space between each other of appr. 30% of the bar width.
I looked at the pointwidth, but the value is 0 and if I change it then it gets only worse. I am using a barchart that displays 24 hours and every hour has 4 bars. The bars are already very small so I like to get rid of the spaces in between and make the bars wider. Are there possiblities to do this?



[quoted text, click to view]
Robert Bruckner [MSFT]
7/24/2004 2:22:13 PM
"Values" represent static chart series. Every chart series is independent
(and has its own legend entry, its own default color etc.).
A (dynamic) category group will group the datapoints within one series.
Therefore, category groups share the same default color and many other
settings within the same chart series.

The Dundas chart control will automatically leave space between different
category groups - especially when you have category groups and multiple
chart series.
I'm not sure why the PointWidth property did not give the expected results.
Which values did you try? By default the internal PointWidth setting is 55,
unless explicitly set in the RDL file. You might want to try values close to
100. Note: the effect of the PointWidth setting is unfortunately not visible
in the chart layout mode, only in preview and server.

--
This posting is provided "AS IS" with no warranties, and confers no rights.


[quoted text, click to view]
display when having different values that makes up the barchart and a
barchart that is made up by a Category Group.
[quoted text, click to view]
therefore they are thicker and better displayed compared to a barchart made
up by a Category group. The bars made up by a Category group have a space
between each other of appr. 30% of the bar width.
[quoted text, click to view]
gets only worse. I am using a barchart that displays 24 hours and every hour
has 4 bars. The bars are already very small so I like to get rid of the
spaces in between and make the bars wider. Are there possiblities to do
this?
[quoted text, click to view]
just 1
Paco
7/24/2004 3:31:02 PM
OK, I did not give it enough tries before.
I tried 100 and it is working now.

Thanks

[quoted text, click to view]
AddThis Social Bookmark Button