Subscribe via RSS Feed

Highchart in Liferay Portlet

February 14, 2013 1 Comment

We have experienced some work related to Liferay Portlet and Highchart.js in our recent development.

The output in Portlet is  -

Highchart in Liferay Portlet

I am sharing the coding requirement here. It is a price comparison data for years.

In the Portlet, I have made use of java collection framework to facilitate Highchart

Data Structure.

Portlet Coding -

<br /><br />List lstchart = (List)<br />renderRequest.getAttribute("chartList");<br /><br />if(lstchart==null)<br />{<br /><br /><%%KEEPWHITESPACE%%>	List lstPrice = &lt;&lt;Get Data from Service&gt;&gt;;<br /><%%KEEPWHITESPACE%%>	HistogramDataBean hdb = new HistogramDataBean();<br /><%%KEEPWHITESPACE%%>	List lstHDB = new ArrayList();<br /><br /><%%KEEPWHITESPACE%%>	double[] monthdata1  =  new double[12];<br /><%%KEEPWHITESPACE%%>	for(int j =0;j	{<br /><%%KEEPWHITESPACE%%>	    monthdata1[j] = 0;<br /><%%KEEPWHITESPACE%%>	}<br /><br /><%%KEEPWHITESPACE%%>	String seriesNamePrev = "";<br /><%%KEEPWHITESPACE%%>	for(int i = 0;i&lt;lstPrice.size();i++)	{<br /><%%KEEPWHITESPACE%%>		Price fp = lstPrice.get(i);<br /><%%KEEPWHITESPACE%%>		if(!seriesNamePrev.equals(""))<br /><%%KEEPWHITESPACE%%>		{<br /><%%KEEPWHITESPACE%%>		    if(!seriesNamePrev.equals(String.valueOf(fp.getM_year())))<br /><%%KEEPWHITESPACE%%>			{<br /><%%KEEPWHITESPACE%%>				hdb.setYear(seriesNamePrev);<br /><%%KEEPWHITESPACE%%>				hdb.setMonthdata(monthdata1);<br /><%%KEEPWHITESPACE%%>				lstHDB.add(hdb);<br /><%%KEEPWHITESPACE%%>				hdb = new HistogramDataBean();<br /><%%KEEPWHITESPACE%%>				monthdata1  =  new double[12];<br /><%%KEEPWHITESPACE%%>				for(int j =0;j&lt;12;j++)<br /><%%KEEPWHITESPACE%%>			        {<br /><%%KEEPWHITESPACE%%>		          		monthdata1[j] = 0;<br /><%%KEEPWHITESPACE%%>				}<br /><%%KEEPWHITESPACE%%>			}<br /><%%KEEPWHITESPACE%%>		}<br /><%%KEEPWHITESPACE%%>		for(int j =0;j&lt;12;j++){<br /><%%KEEPWHITESPACE%%>		      if(fp.getM_month()==(j+1))<br /><%%KEEPWHITESPACE%%>				{<br /><%%KEEPWHITESPACE%%>				monthdata1[j] = fp.getPrice();<br /><%%KEEPWHITESPACE%%>				}<br /><%%KEEPWHITESPACE%%>			}<br /><%%KEEPWHITESPACE%%>			seriesNamePrev = String.valueOf(fp.getM_year());<br /><%%KEEPWHITESPACE%%>		}<br /><%%KEEPWHITESPACE%%>		hdb.setYear(seriesNamePrev);<br /><%%KEEPWHITESPACE%%>		hdb.setMonthdata(monthdata1);<br /><%%KEEPWHITESPACE%%>		lstHDB.add(hdb);<br /><%%KEEPWHITESPACE%%>		renderRequest.setAttribute("chartList", lstHDB);<br /><%%KEEPWHITESPACE%%>	}<br /><br />

For easy understanding, I am sharing the HistogramDataBean Structure here.

 
package com.util;

public class HistogramDataBean {
	private String year;
	public String getYear() {
		return year;
	}
	public void setYear(String year) {
		this.year = year;
	}
	public double[] getMonthdata() {
		return monthdata;
	}
	public void setMonthdata(double[] monthdata) {
		this.monthdata = monthdata;
	}
	private double[] monthdata  =  new double[12];
}

And I am attaching the full jsp and highchart coding for the Highchart to work here

The solution worked Wonderfully.

Enter your email address:

Delivered by FeedBurner