PDA

View Full Version : BarChart in Portlet



ocho79
07-20-2006, 09:24 AM
Hi there,

I'm about to finish my first own dashboard in a portal using the portlets that are coming with the pci (path: \\org\\pentaho\\ui\\portlet\\). Everything works fine.

The last thing that I want to show is a barchart in a portlet - instead of the piechart, that comes with the pci.

Can I use one of the two charting portlets that are in \\org\\pentaho\\ui\\portlet\\charting. There is one, which you guys use for creating the piechart (PieDatasetChartPortlet.java) portlet, and I guess I cannot use it for barcharts, right? Can I use the other one (CategoryDatasetChartPortlet.java)? Or do I need to create a new portlet?

Thanks for helping me!

besos,
Myra

guzaldon
07-20-2006, 10:23 AM
I'm kind of in the same boot currently. I wanted to add a line chart like they have in the steel-wheels dashboard but in the jboss dashboard. I have tried some of the different portlets and it looks like they wont work stock. So we are off to create our own portlet plugins I think. It probably wouldn't hurt to use one of the portlets already created for a starter.

I wonder if someone from pentaho could give us some pointers or point us in the direction for some Docs.

I'm going to check out the Docs agian to see if there is anythign in there.

Sorry I'm not much help but anything you find out please post back I'll do the same.

Thanks,

Nic

ocho79
07-20-2006, 11:30 PM
Hei Nic,

thanks for your answer - well lets see what we can do maybe together . I hope we can stay in contact for that topic.

I already have my book "Portlets - the easy way" but since I haven't written my own one yet I think I won't make it without help. Maybe some of the Admins can give us some hints!

guzaldon
07-21-2006, 08:10 AM
I haven't made one yet either but I have spent a lot of time looking at them. So hopefully we can do it!

And I bet they will when we start having a problem or a question.. And who knows this could help outline some docs for them as well. I probably wont be starting on mine till next week. and i hang out on the boards a lot so I'm sure we'll be able to keep contact.

May the forces be with us,

Nic

guzaldon
07-21-2006, 11:53 AM
I just did a SVN update and I see that there are some new portlets as some charting components.

A ../src/org/pentaho/ui/component/charting/TimeSeriesCollectionChartComponent.java
A ../src/org/pentaho/ui/component/charting/XYSeriesCollectionChartComponent.java
A ../src/org/pentaho/ui/portlet/charting/TimeSeriesCollectionChartPortlet.java
A../src/org/pentaho/ui/portlet/charting/XYSeriesCollectionChartPortlet.java

Still no bar chart but there are a couple more examples to refernce.

Nic

ocho79
07-22-2006, 11:45 AM
Hei,

thanks for that hint!

But have you seen any documentation on the xml descriptors for generating thoses charts. I am not sure, but I think they doen't have anything in common with the jfree-charting, right?

Offtopic but maybe also interesting to you:
I discovered that Jpivot is offering a portlet for integrating the OLAP function into portlets. Well interesting but I think the pentaho JSP based option still is better b/c a portlet usually is too small - even when you maximize it. Currently I am working on adding a bit more security to the JPivot Jsp but I am also stuck on that (see my other post in the framework section of the board).

First I was completely disappointed of the framework but since I nearly finished my first (small) enterprise dashboard I am looking forward to work more with it.

guzaldon
07-22-2006, 02:57 PM
First off thanks for not cross posting. :-)

and I do think that the jfree-charting and the xml defs do have a bit in common but just don't have all the functionality of the jfree-charting. I have seen that the "steel wheels" examples do have some good coments in them in regards to what the different lines do. as well might be a good place to get some hints for building these portlets.

I would agree that it was a bit disappointing when I first started and was blind to how flexible everything was. Now I am not blind and I'm not seeing much that would be impossible. Special when you start to write your own JSPs.

Another really fun componet is Kettle you might want to check that out if you haven't already. Honestly it's fun and Matt is pretty good at getting back to you or another kettle dev will. Just besure to read the docs and the forums for related issues before you start posting it'll make things easier for everyone like it does here.

Nic

martincgn
09-20-2006, 03:21 AM
if anyone is interested, i found a solution for the barchart.
I copied the PieDatasetChartPortlet an called it BarDatasetChartPortlet , also the PieDatasetChartComponent and called it BarDatasetChartComponent.

In the method public void doPortletView(...) in BarDatasetChartPortlet you have to replace the following code:


chartComponent = new PieDatasetChartComponent(chartDefinitionStr, urlFactory, messages);
with this

chartComponent = new BarDatasetChartComponent(chartDefinitionStr, urlFactory, messages);


In the method public Dataset createChart(...) in BarDatasetChartPortlet you have to replace the following code:


PieDatasetChartDefinition chartDefinition = new PieDatasetChartDefinition((IPentahoResultSet) values, byRow, chartAttributes);
with this

CategoryDatasetChartDefinition chartDefinition = new CategoryDatasetChartDefinition((IPentahoResultSet) values, byRow, chartAttributes);


After this you have to edit your portlet.xml, pentaho-object.xml accordingly.
Now you can edit the value of |chart-type| in budgetsPiechart.xml to BarChart

martincgn
09-20-2006, 03:21 AM
if anyone is interested, i found a solution for the barchart.
I copied the PieDatasetChartPortlet an called it BarDatasetChartPortlet , also the PieDatasetChartComponent and called it BarDatasetChartComponent.

In the method public void doPortletView(...) in BarDatasetChartPortlet you have to replace the following code:


chartComponent = new PieDatasetChartComponent(chartDefinitionStr, urlFactory, messages);
with this

chartComponent = new BarDatasetChartComponent(chartDefinitionStr, urlFactory, messages);


In the method public Dataset createChart(...) in BarDatasetChartPortlet you have to replace the following code:


PieDatasetChartDefinition chartDefinition = new PieDatasetChartDefinition((IPentahoResultSet) values, byRow, chartAttributes);
with this

CategoryDatasetChartDefinition chartDefinition = new CategoryDatasetChartDefinition((IPentahoResultSet) values, byRow, chartAttributes);


After this you have to edit your portlet.xml, pentaho-object.xml accordingly.
Now you can edit the value of |chart-type| in budgetsPiechart.xml to BarChart

martincgn
09-20-2006, 03:22 AM
if anyone is interested, i found a solution for the barchart.
I copied the PieDatasetChartPortlet an called it BarDatasetChartPortlet , also the PieDatasetChartComponent and called it BarDatasetChartComponent.

In the method public void doPortletView(...) in BarDatasetChartPortlet you have to replace the following code:


chartComponent = new PieDatasetChartComponent(chartDefinitionStr, urlFactory, messages);
with this

chartComponent = new BarDatasetChartComponent(chartDefinitionStr, urlFactory, messages);


In the method public Dataset createChart(...) in BarDatasetChartPortlet you have to replace the following code:


PieDatasetChartDefinition chartDefinition = new PieDatasetChartDefinition((IPentahoResultSet) values, byRow, chartAttributes);
with this

CategoryDatasetChartDefinition chartDefinition = new CategoryDatasetChartDefinition((IPentahoResultSet) values, byRow, chartAttributes);


After this you have to edit your portlet.xml, pentaho-object.xml accordingly.
Now you can edit the value of |chart-type| in budgetsPiechart.xml to BarChart

kreynaldo
11-23-2006, 06:59 AM
As I could see you haven't still get a satisfactory solution, so I'll give you my solution based on pentaho's samples.
First of all, if you want to create a BarChart, as well as LineChart and AreaChart, then you will need to use org.pentaho.ui.portlet.charting.CategoryDatasetChartPortlet
The problem is that there is no sample of this portlet predefined, but it works fine.
So here it is:
1- The portlet definition in Portlet.xml looks like:


<portlet>
<portlet-name>CategoryDatasetChartPortlet</portlet-name>
<portlet-class>org.pentaho.ui.portlet.charting.CategoryDatasetChartPortlet</portlet-class>
<supports>
<mime-type>text/html</mime-type>
<portlet-mode>VIEW</portlet-mode>
</supports>
<portlet-info>
<title>Category Dataset Chart Portlet</title>
</portlet-info>
<portlet-preferences>
<preference>
<name>chart</name>
<value>samples/portal/budgets.categoryChart.xml</value>
</preference>
<preference>
<name>drill-url</name>
<value>/pentaho/Pivot?solution=samples&path=analysis&action=query1.xaction&region=.[{REGION}]&department=.[{DEPARTMENT}]&position=.[{POSITION}]</value>
</preference>
<preference>
<name>outer-params</name>
<value>REGION;DEPARTMENT</value>
</preference>
<preference>
<name>inner-param</name>
<value>POSITION</value>
</preference>
</portlet-preferences>
</portlet>

2- You need to define the chart definition. Here is a sample chart definition from my own:



<chart>
<chart-type>BarChart</chart-type>
<data>
<data-solution>samples</data-solution>
<data-path>portal</data-path>
<data-action>headcount_actual_by_region.xaction</data-action>
<data-output>rule-result</data-output>
<data-name>POSITIONTITLE</data-name>
<data-value>VARIANCE</data-value>
<data-orientation>columns</data-orientation>
</data>
<width>350</width>
<height>135</height>
<title></title>
<title-position>TOP</title-position>
<title-font>
<font-family>Serif</font-family>
<size>36</size>
<is-bold>false</is-bold>
<is-italic>false</is-italic>
</title-font>
<subtitle></subtitle>
<domain-title></domain-title>
<range-title></range-title>
<!-- chart-background type="gradient">
<x1>0.0</x1>
<y1>0.0</y1>
<color1>#000000</color1>
<x2>200.0</x2>
<y2>200.0</y2>
<color2>#FFFFFF</color2>
<cyclic>true</cyclic>
</chart-background -->
<!-- chart-background type="texture">
<x1>0.0</x1>
<y1>0.0</y1>
<x2>20.0</x2>
<y2>20.0</y2>
<texture-image>test\\charts\\texture.png</texture-image>
</chart-background -->
<!-- plot-background type="image">test/charts/ChartBackground.jpg</plot-background -->
<orientation>Vertical</orientation>
<is-3D>false</is-3D>
<is-stacked>false</is-stacked>
<category-label-rotation>0</category-label-rotation>
<border-visible>false</border-visible>
<border-paint>#3399FF</border-paint>
<!-- url-template></url-template -->
<!-- paramName></paramName -->
<!-- series-name></series-name -->
<color-palette>
<color>#336699</color>
<color>#99CCFF</color>
<color>#999933</color>
<color>#666699</color>
<color>#CC9933</color>
<color>#006666</color>
<color>#3399FF</color>
</color-palette>
<include-legend>false</include-legend>
</chart>

I've commented out some xml nodes, but you can use them at will.
Note that you must specify the <chart-type>, whose valid values are: BarChart, LineChart and AreaChart, as long as I know.
You can refer to the source code to get more information on chart definition, as well as other chart samples, since all portlets use the same chart component to generate its output.
Good luck,
Karel