2016-02-10 170 views
0

这里现有的功能设置默认值就是一个例子:在斯卡拉

import org.jfree.chart.plot.PlotOrientation 
import org.jfree.chart.{ChartFactory => cf, JFreeChart} 
import org.jfree.data.xy.XYDataset 


package object sfreechart { 
    object xyl { 
    def xyline(
       dataset: XYDataset, 
       title: String = "XY line chart", xAxisLabel: String = "x", yAxisLabel: String = "y", 
       orientation: PlotOrientation = PlotOrientation.VERTICAL, legend: Boolean = true, 
       tooltips: Boolean = true, urls: Boolean = true 
      ): JFreeChart = { 
     cf.createXYLineChart(
     title, xAxisLabel, yAxisLabel, 
     dataset, orientation, legend, 
     tooltips, urls 
    ) 
    } 
    } 
} 

我只是想在JFreeChart的一个绘图功能提供了合理的默认值,使图表可以没有太多的仪式来创建。上面的代码工作正常,但涉及一些无聊的样板。有一个聪明的窍门吗?

理想我应该只需要做这样的事情:

val xyline = cf.createXYLineChart.setDefaults(title = "XY line chart", ...) 

回答

1

没有任何这样的伎俩。另外,恕我直言,这里真的没有任何样板。它的最低限度你可以写传达这个要求。