Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created November 3, 2016 10:22
Show Gist options
  • Select an option

  • Save Sciss/cc39d6b7f12fe7245f123696dcc9c971 to your computer and use it in GitHub Desktop.

Select an option

Save Sciss/cc39d6b7f12fe7245f123696dcc9c971 to your computer and use it in GitHub Desktop.
trait Histo {
def bins: Array[Int]
def name: String
}
def mkChart(histo: Histo): XYChart = {
val data = histo.bins.zipWithIndex.map { case (num, idx) =>
histo.center(idx) -> num
} .toVector
import scalax.chart.api._
val barWidth = histo.center(1) - histo.center(0)
val fihData = data.toXYSeriesCollection(histo.name)
val withWidth = new XYBarDataset(fihData, barWidth)
val chart = XYBarChart(withWidth, title = s"Histogram for ${histo.name}")
val plot = chart.plot
plot.getRenderer.setSeriesPaint(0, Color.darkGray)
chart
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment