2011年7月25日月曜日

現場で使えるJavaライブラリーのサンプルを丸写ししてみた。

最近次のような本が発売されました。

現場で使えるJavaライブラリ
竹添 直樹 (著), 島本 多可子 (著), 小津 美夕紀 (著), 亀井 隆司 (著)
翔泳社 (2011/7/16)







で、早速そこに載っているライブラリーを試してみました。

charts4j

各種のチャートをWeb上で処理してくれるライブラリーです。

@Grab(group='com.googlecode.charts4j', module='charts4j', version='1.3')
import com.googlecode.charts4j.*;

def plot1 = Plots.newBarChartPlot(Data.newData(20, 100, 10, 30), Color.BLUE)
def plot2 = Plots.newBarChartPlot(Data.newData(50,  80, 30, 70), Color.RED)

def chart = GCharts.newBarChart(plot1, plot2)

chart.setTitle('Sample')
chart.setSize(400, 300)
chart.setBarWidth(40)
chart.setGrid(10, 10, 2, 2)
chart.addXAxisLabels(AxisLabelsFactory.newAxisLabels('A', 'B', 'C', 'D'))
chart.addYAxisLabels(AxisLabelsFactory.newAxisLabels('0', '50', '100'))

def url = chart.toURLString()


実行した結果のURL

http://chart.apis.google.com/chart?cht=bvg&chxt=y,x&chs=400x300&chtt=Sample&chbh=40,4,8&chg=10.0,10.0,2,2&chco=0000FF,FF0000&chd=e:Mz..GaTN,gAzMTNsz&chxl=0:|0|50|100|1:|A|B|C|D


実行結果の画像

なかなかやりおる。
コードがGroovyっぽくないので、すこしリファクタリングしないとダメですね。

0 件のコメント:

コメントを投稿