<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Answers to: How to use charts in Html user dialogs?</title><link>https://answers.axonivy.com/questions/18/how-to-use-charts-in-html-user-dialogs</link><description>&lt;p&gt;I need to show charts in my dialogs but I have no idea how to use them in Xpert.ivy...&lt;/p&gt;</description><atom:link href="https://answers.axonivy.com/questions/18/how-to-use-charts-in-html-user-dialogs" rel="self"></atom:link><language>en</language><lastBuildDate>Tue, 08 Oct 2013 14:43:27 -0400</lastBuildDate><item><title>Answer by SupportIvyTeam</title><link>https://answers.axonivy.com/questions/18/how-to-use-charts-in-html-user-dialogs/19</link><description>&lt;p&gt;Luckily PrimeFaces offers a lot of chart components. As an example we show what you can do with bar, line and gauge charts. &lt;/p&gt;
&lt;p&gt;&lt;img alt="alt text" src="/upfiles/charts.png"&gt;&lt;/p&gt;
&lt;p&gt;The special thing about using charts is the correct &lt;code&gt;ChartModel&lt;/code&gt;. For line and bar charts you need the &lt;code&gt;CartesianChartModel&lt;/code&gt;, for the gauge chart you need a &lt;code&gt;MeterGaugeChartModel&lt;/code&gt;. Here the model for bar charts:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import org.primefaces.model.chart.CartesianChartModel;
import org.primefaces.model.chart.ChartSeries;

in.barModel = new CartesianChartModel();

ChartSeries boys = new ChartSeries();  
boys.setLabel("Boys");       
boys.set("2004", 120);  
boys.set("2005", 100);  
boys.set("2006", 44);  
boys.set("2007", 150);  
boys.set("2008", 25);

ChartSeries girls = new ChartSeries();  
girls.setLabel("Girls");      
girls.set("2004", 52);  
girls.set("2005", 60);  
girls.set("2006", 110);  
girls.set("2007", 135);  
girls.set("2008", 120);

in.barModel.addSeries(boys);  
in.barModel.addSeries(girls);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;You see the &lt;code&gt;ChartesianChartModel&lt;/code&gt; has no direct data, it uses objects of the type &lt;code&gt;ChartSeries&lt;/code&gt;. Line charts work exactly the same way, the sole difference is that you will use &lt;code&gt;LineChartSeries&lt;/code&gt; instead of &lt;code&gt;ChartSeries&lt;/code&gt;. The gauge chart uses a little different model, the &lt;code&gt;MeterGaugeChartModel&lt;/code&gt;. It gets the value of the gauge and the color intervals as arguments of the constructor.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;import org.primefaces.model.chart.MeterGaugeChartModel;
List&amp;lt;Number&amp;gt; intervals = new List&amp;lt;Number&amp;gt;();
intervals.add(20);
intervals.add(50);
intervals.add(120);
intervals.add(220);
in.meterGaugeModel = new MeterGaugeChartModel(140, intervals);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The embedding of the charts in the Html user dialog is plain and simple:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;&amp;lt;p:lineChart value="#{data.lineModel}" legendPosition="e" zoom="true" animate="true"  
        title="Linear Chart" minY="0" maxY="10" style="width:400px;"/&amp;gt;  
&amp;lt;p:barChart id="basic" value="#{data.barModel}" legendPosition="ne"  
        title="Bar Chart" min="0" max="200" style="width:400px" animate="true"/&amp;gt;  
&amp;lt;p:meterGaugeChart value="#{data.meterGaugeModel}" showTickLabels="false" labelHeightAdjust="110" intervalOuterRadius="130"  
        seriesColors="66cc66, 93b75f, E7E658, cc6666" style="width:400px;height:250px" title="Process state" label="critical"/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;For more information, please see the &lt;a href="http://xpert-ivy-hacker-source-code.googlecode.com/svn/trunk/Forms"&gt;example project&lt;/a&gt; or have a look at the &lt;a href="http://www.primefaces.org/showcase/ui/areaChart.jsf"&gt;PrimeFaces Charts demo.&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br&gt;
&lt;br&gt;
Note: This question and answer was &lt;a href="http://blog.xpertivyhacker.ch/2013/01/xpert-ivy-code-rezept-primefaces-charts-anzeigen.html"&gt;originally posted&lt;/a&gt; by Heinrich Spreiter on his &lt;a href="http://blog.xpertivyhacker.ch/"&gt;Xpert.ivy Hacker blog&lt;/a&gt;. Henry, many thanks to you for your enthusiastic work. &lt;/p&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">SupportIvyTeam</dc:creator><pubDate>Tue, 08 Oct 2013 14:43:27 -0400</pubDate><guid>https://answers.axonivy.com/questions/18/how-to-use-charts-in-html-user-dialogs/19</guid></item></channel></rss>