Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
creating chart from table colum names
rundolph
Hello List,<br />
<br />
I'm quite new to birt and I need to design a pie chart using availability values from nagios.<br />
The corresponding tdata set supplies the data as followes:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>| Percent_OK| Percent_Down| Percent_Warning |
| 99 | 1 | 0 |</pre>
<br />
So I need to create a pie chart with "catogory definition" as colum names and and "slice size definition" as its values.<br />
<br />
As I figured out, i can only create a chart when the names and values are in seperate colums like<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>status | value
Percent_OK | 99
Percent_Down | 1
Percent_Warning | 0</pre>
<br />
But in my case that is not possible.<br />
Can anyone give me some hints or solutions for this? I think it is a common scenario?<br />
Thank you and best regards<br />
<br />
Rundolph
Find more posts tagged with
Comments
Hans_vd
Hi Rundolph,<br />
<br />
Are you selecting the from a database?<br />
Can you write your query like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>SELECT 'Percent_OK' AS status,
percent_ok AS status_value
FROM [your_table]
UNION ALL
SELECT 'Percent_Down' AS status,
percent_down AS status_value
FROM [your_table]
UNION ALL
SELECT 'Percent_warning' AS status,
percent_warning AS status_value
FROM [your_table]</pre>
<br />
Hope this helps<br />
Hans
rundolph
Hi Hans,<br />
<br />
thank you for your quick response. Yes, I know this works easy but it does not work with report parameters.<br />
The only solution would be to assign variables to the data set. But there seems to be only possible asigning report parameters.<br />
<br />
My Data set looks as followes:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>SELECT round(avg(PERCENT_TIME_OK_SCHEDULED +
PERCENT_TIME_OK_UNSCHEDULED),2) Percent_OK,
round(avg(PERCENT_TIME_WARNING_UNSCHEDULED),2) Percent_Warning,
round(avg(PERCENT_TIME_CRITICAL_UNSCHEDULED),2) Percent_Down,
round(avg(PERCENT_TIME_CRITICAL_SCHEDULED +
PERCENT_TIME_UNKNOWN_SCHEDULED +
PERCENT_TIME_WARNING_SCHEDULED),2) Downtime,
round(avg(PERCENT_TIME_UNKNOWN_UNSCHEDULED),2) Unknown,
round(avg(PERCENT_TIME_UNDETERMINED_NOT_RUNNING +
PERCENT_TIME_UNDETERMINED_NO_DATA),2) 'no Data'
FROM dashboard.service_availability
where HOST_NAME = ?
and SERVICE_NAME = ?
and DATESTAMP between ? and ?
group by SERVICE_NAME;</pre> <br />
<br />
With union selects any select needs the "where" clause so I need to assign always a ? or a fixed variable.<br />
Have you assigned parameters or variables to this union selects?<br />
Regards<br />
<br />
Ralf
Hans_vd
Hi Ralf,<br />
<br />
There's an interesting article on reusing parameters in a birt dataset <a class='bbc_url' href='
http://enterprisesmartapps.wordpress.com/2011/01/10/re-using-parameters-in-birt-data-set/'>here</a>
. But you will have to add a where clause to every select statement of course. You're query will look like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
WITH params (
SELECT ? AS p_host_name,
? AS p_service_name,
? AS p_date_from,
? AS p_date_to
FROM dual
)
SELECT 'Percent_OK' AS status,
round(avg(PERCENT_TIME_OK_SCHEDULED + PERCENT_TIME_OK_UNSCHEDULED),2) AS status_value
FROM dashboard.service_availability,
params
WHERE HOST_NAME = p_host_name
AND SERVICE_NAME = p_service_name
AND DATESTAMP BETWEEN p_date_from AND p_date_to
GROUP BY SERVICE_NAME;
UNION ALL
SELECT 'Percent_Warning'
round(avg(PERCENT_TIME_WARNING_UNSCHEDULED),2) AS status_value
FROM dashboard.service_availability,
params
WHERE HOST_NAME = p_host_name
AND SERVICE_NAME = p_service_name
AND DATESTAMP BETWEEN p_date_from AND p_date_to
GROUP BY SERVICE_NAME;
UNION ALL
SELECT 'Percent_Down' AS status,
round(avg(PERCENT_TIME_CRITICAL_UNSCHEDULED),2) AS status_value
FROM dashboard.service_availability,
params
WHERE HOST_NAME = p_host_name
AND SERVICE_NAME = p_service_name
AND DATESTAMP BETWEEN p_date_from AND p_date_to
GROUP BY SERVICE_NAME;
UNION ALL
...
</pre>
<br />
<br />
About the use of dual, you can read about that in the comments of the blogpost I linked to<br />
<br />
<br />
Regards<br />
Hans
rundolph
Hello Hans,
thank you for that very good solution. However, this data set is little ressource intensive, but it works. :-)
Best regards
Rundolph
Hans_vd
Hi Ralf,<br />
<br />
If you're looking for a solution that is less resource intensive, you might want to try this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
WITH columns_to_rows AS (
SELECT ROWNUM rn
FROM dual
CONNECT BY ROWNUM <= 6
)
SELECT CASE ctr.rn
WHEN 1 THEN 'Percent_OK'
WHEN 2 THEN 'Percent_Warning'
WHEN 3 THEN 'Percent_Down'
WHEN 4 THEN 'Downtime'
WHEN 5 THEN 'Unknown'
WHEN 6 THEN 'no Data'
END status,
CASE ctr.rn
WHEN 1 THEN round(avg(PERCENT_TIME_OK_SCHEDULED + PERCENT_TIME_OK_UNSCHEDULED),2)
WHEN 2 THEN round(avg(PERCENT_TIME_WARNING_UNSCHEDULED),2)
WHEN 3 THEN round(avg(PERCENT_TIME_CRITICAL_UNSCHEDULED),2)
WHEN 4 THEN round(avg(PERCENT_TIME_CRITICAL_SCHEDULED + PERCENT_TIME_UNKNOWN_SCHEDULED + PERCENT_TIME_WARNING_SCHEDULED),2)
WHEN 5 THEN round(avg(PERCENT_TIME_UNKNOWN_UNSCHEDULED),2)
WHEN 6 THEN round(avg(PERCENT_TIME_UNDETERMINED_NOT_RUNNING + PERCENT_TIME_UNDETERMINED_NO_DATA),2)
END status_value
FROM dashboard.service_availability,
columns_to_rows ctr
WHERE HOST_NAME = ?
AND SERVICE_NAME = ?
AND DATESTAMP BETWEEN ? AND ?
GROUP BY SERVICE_NAME, ctr.rn
</pre>
<br />
This solution also makes use of the WITH clause, but in this case it is used to generate a number for each row you'll have in the dataset. Next, in the query the rownumbers are joined to your original query and in the select, depending on the rownumber another function or sum or whatever you want is performed on the data. Don't forget to add the rownumber to the GROUP BY, to make things work.<br />
<br />
Some of the syntax may be Oracle specific, but I'm sure you'll find an equivalent for whatever database it is that you are executing the query on.<br />
<br />
Regards<br />
Hans
rundolph
Thank you, Hans. The Database is a Mysql Database and does not support the with clause. But I will try to use your hints, as soon as they become necessary. For me, assigning each report parameter to each union select works too. :-)