Code Monkey home page Code Monkey logo

scala-chart's Introduction

Scala Chart Library

scala-chart is a Scala library for creating and working with charts. It wraps JFreeChart, much like scala-swing does with the original javax.swing package. This project is released under the same license as JFreeChart to make them fully license-compatible. Checkout the API.

Example Usage

libraryDependencies += "com.github.wookietreiber" %% "scala-chart" % "latest.integration"
<dependency>
   <groupId>com.github.wookietreiber</groupId>
   <artifactId>scala-chart_${scala.version}</artifactId>
   <version>latest.integration</version>
</dependency>

Imports

You can import nearly all of the scala-chart functionality (except the views, see below) with the following lines:

import scalax.chart._
import scalax.chart.Charting._

You can use the conversions to convert from ordinary Scala collections to the datasets used by JFreeChart:

val data    = Seq((1,2),(2,4),(3,6),(4,8))
val dataset = data.toXYSeriesCollection("some points")

These datasets can be used by the chart factories, which differ from the JFreeChart ones in the aspect, that they make heavy use of default arguments, so you have to type as less as possible:

val chart = XYLineChart(dataset)

The first argument is always the dataset which is the only required argument. For better readability of your own code, you should name the other arguments:

val chart = XYLineChart(dataset, title = "My Chart of Some Points")

There are also some enrichments for the charts themselves to display them in a window or save them to disk:

chart.show
chart.saveAsPNG(new java.io.File("/tmp/chart.png"), (1024,768))
chart.saveAsJPEG(new java.io.File("/tmp/chart.jpg"), (1024,768))
chart.saveAsPDF(new java.io.File("/tmp/chart.pdf"), (1024,768))

There are also implicit conversions / views available, but they are not contained by the above imports, because of ambiguity issues which may arise with implicit conversions. There are different imports available for different kinds of datasets, e.g.:

import scalax.chart.views.XYDatasetViews._
val data = Seq((1,2),(2,4),(3,6),(4,8))
val chart = XYLineChart(data, title = "My Chart of Some Points")

Import these with care, it's most likely better to use the explicit conversions as shown above.


endorse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.