是否有更好的界面来为Zeppelin添加Highcharts支持? [英] Are there better interface to add Highcharts support to Zeppelin

查看:162
本文介绍了是否有更好的界面来为Zeppelin添加Highcharts支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

因为在一个apply()方法中放入几个列表是有点难以阅读的。


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.

解决方案

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.

这篇关于是否有更好的界面来为Zeppelin添加Highcharts支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆