Ofchart plugin available for Grails, makes it is easy to integrate Open Flash Chart.
The plugin can be downloaded from http://grails.org/plugin/ofchart
The documentation is available at
http://mybytes.wordpress.com/2009/03/09/grails-open-flash-chart-06-is-out/
Though the Open Flash Chart has number of chart options - ofchart plugin documentation has limited information. I believe the documentation work is in progress and may be available anytime soon. An inquisitive mind can experiment and try to accomplish most of the features in Open Flash Chart.
Best place to start is to read the API documentation
A simple example I tried - overlaying a Bar chart and Line chart on a single Chart.
It requires a Grails controller and a GSP as listed below. We can include the "action" to render the chart in any of your existing controllers.
Following is the GSP that includes the above chart.
The plugin can be downloaded from http://grails.org/plugin/ofchart
The documentation is available at
http://mybytes.wordpress.com/2009/03/09/grails-open-flash-chart-06-is-out/
Though the Open Flash Chart has number of chart options - ofchart plugin documentation has limited information. I believe the documentation work is in progress and may be available anytime soon. An inquisitive mind can experiment and try to accomplish most of the features in Open Flash Chart.
Best place to start is to read the API documentation
A simple example I tried - overlaying a Bar chart and Line chart on a single Chart.
It requires a Grails controller and a GSP as listed below. We can include the "action" to render the chart in any of your existing controllers.
import jofc2.model.Chart
import jofc2.model.elements.LineChart
import jofc2.model.axis.YAxis
import jofc2.model.axis.XAxis
import jofc2.model.axis.Label
import jofc2.model.elements.AreaHollowChart
import jofc2.model.elements.PieChart
import jofc2.model.axis.Label.Rotation
import jofc2.model.elements.BarChart
import jofc2.OFC
import jofc2.model.elements.FilledBarChart
import jofc2.model.elements.SketchBarChart
import jofc2.model.elements.HorizontalBarChart
import jofc2.model.elements.ScatterChart
import java.math.MathContext
import jofc2.model.elements.StackedBarChart
import jofc2.model.elements.StackedBarChart.StackValue
class ChartController {
def index = { }
def MANY_LINES = {
}
def data1 = new ArrayList < Number>();
def data2 = new ArrayList < Number>();
def data3 = new ArrayList < Number>();
def rand = new Random();
for (int i = 0; i <: 9; i++) {
data1.add(1 + rand.nextInt(5));
data2.add(7 + rand.nextInt(5));
data3.add(14 + rand.nextInt(5));
}
render new Chart("Three lines example").setYAxis(new YAxis().setRange(0, 20, 5)).addElements(
new LineChart(LineChart.Style.DOT).setWidth(4).setColour("#DFC329").setDotSize(5).addValues(data1),
new LineChart(LineChart.Style.HOLLOW).setWidth(1).setColour("#6363AC").setDotSize(5).addValues(data2),
new LineChart().setWidth(1).setColour("#5E4725").setDotSize(5).addValues(data3))
.addElements(new BarChart().addValues(9, 8, 7, 6, 5, 4, 3, 2, 1))
}
}
Following is the GSP that includes the above chart.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="layout" content="main" />
<title>Chart example</title>
<ofchart:resources/>
</head>
<body>
<div class="body">
<h1>Chart Example</h1>
<ofchart:chart name="demo-chart" url="${ createLink( controller:'chartController', action:'MANY_LINES' )}"
width="400" height="200"/>
</div>
</body>
</html>
Comments
Post a Comment