Are there better interface to add Highcharts support to Zeppelin

醉酒当歌 提交于 2019-12-04 04:32:07

问题


Apache Zeppelin has good support for AngularJS. While there is a gap between Scala and Javascript.

I am trying to add Highcharts support to Zeppelin to fill in this gap. The main goal is to plot it simply directly from Spark DataFrame.

After couple round refactor, I come up with the following interface.

github.com/knockdata/zeppelin-highcharts

Here are two options. Which option is better?

Option A

This is an example to plot highcharts.

highcharts(bank,
  "marital",
  List("name" -> "age", "y" -> avg(col("balance")), "orderBy" -> col("age")),
  new Title("Marital Job Average Balance").x(-20),
  new Subtitle("Source: Zeppelin Tutorial").x(-20),
  new XAxis("Age").typ("category"),
  new YAxis("Balance(¥)").plotLines(Map("value"->0, "width"->1)),
  new Tooltip().valueSuffix("¥"),
  new Legend().layout("vertical").align("right").verticalAlign("middle")
)

Here is the code without extra option.

highcharts(bank,
           "marital",
           List("name" -> "age", 
           "y" -> avg(col("balance")), 
           "orderBy" -> col("age")))

Option B

I come up this option with inspiring by @honnix's answer. It has more syntactic sugar.

highcharts(bank).series("marital")
  .data("name" -> "age", "y" -> avg(col("balance")))
  .orderBy(col("age"))
  .title(Title("Marital Job Average Balance").x(-20))
  .subtitle(Subtitle("Source: Zeppelin Tutorial").x(-20))
  .xAxis(XAxis("Age").typ("category"))
  .yAxis(YAxis("Balance(¥)").plotLines("value"->0, "width"->1))
  .tooltip(Tooltip().valueSuffix("¥"))
  .legend(Legend().layout("vertical").align("right").verticalAlign("middle"))
  .plot

A simple plot without option will be

highcharts(bank).series("marital")
  .data("name" -> "age", "y" -> avg(col("balance")))
  .orderBy(col("age"))
  .plot

It will generate a chart here.


回答1:


It would be good to have some kind of chaining methods to pass in those parameters, because putting a few lists together in one apply() method is a little bit hard to read.



来源:https://stackoverflow.com/questions/38530410/are-there-better-interface-to-add-highcharts-support-to-zeppelin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!