https://github.com/pishen/chart4s
Draw a web chart by Scala
https://github.com/pishen/chart4s
chart plot scala
Last synced: 9 months ago
JSON representation
Draw a web chart by Scala
- Host: GitHub
- URL: https://github.com/pishen/chart4s
- Owner: pishen
- License: apache-2.0
- Created: 2015-07-10T15:38:10.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2019-09-17T02:33:45.000Z (almost 7 years ago)
- Last Synced: 2023-03-16T12:45:27.690Z (over 3 years ago)
- Topics: chart, plot, scala
- Language: Scala
- Homepage:
- Size: 736 KB
- Stars: 37
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# chart4s
Draw a web chart by Scala.

The charts are generated by [C3.js](http://c3js.org/). Support for other JavaScript libraries may come in the future.
## Installation
Add the following to your `build.sbt`:
```
libraryDependencies += "net.pishen" %% "chart4s" % "0.2.0"
resolvers += Resolver.bintrayRepo("pishen", "maven")
```
Then, add the import statements to your code:
```scala
import chart4s.c3._
```
## Supported charts
### Line Chart
```scala
val lines = Seq(
"a" -> Seq(3.1,6.4,2.3,7.5,5.0,8.9),
"b" -> Seq(5.4,3.3,7.0,2.7,3.9,5.2)
)
val xValues = Seq(0.1, 0.2, 0.3, 0.45, 0.5, 0.6)
LineChart(lines, xValues).draw
```
### Bar Chart
```scala
val data = Seq(
"a" -> Seq(3.1,6.4,2.3,7.5,5.0,8.9,7.7),
"b" -> Seq(5.4,3.3,7.0,2.7,3.9,5.2,9.1)
)
val xValues = Seq("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat")
BarChart(data, xValues).draw
```
### Pie Chart
```scala
PieChart(Seq("a" -> 5, "b" -> 3, "c" -> 11)).draw
```
### Stacked Line Chart
```scala
val lines = Seq(
"a" -> Seq(3.1,6.4,2.3,7.5,5.0,8.9),
"b" -> Seq(5.4,3.3,7.0,2.7,3.9,5.2)
)
val xValues = Seq(0.1, 0.2, 0.3, 0.45, 0.5, 0.6)
StackedLineChart(lines, xValues).draw
```
### Timeseries Chart
```scala
import java.time.LocalDate //also works for LocalDateTime
val lines = Seq(
"a" -> Seq(3.1,6.4,2.3,7.5,5.0,8.9),
"b" -> Seq(5.4,3.3,7.0,2.7,3.9,5.2)
)
val now = LocalDate.now
val timeValues = Seq(0, 1, 2, 4, 5, 6).map(d => now.plusDays(d))
TimeseriesChart(lines, timeValues).draw
```
### XY Line Chart
```scala
XYLineChart(Seq(
"a" -> Seq(1 -> 1, 2 -> 2, 3 -> 3, 4 -> 5, 5 -> 8, 6 -> 13),
"b" -> Seq(5 -> 1, 6 -> 2, 7 -> 3, 8 -> 5, 9 -> 8, 10 -> 13)
)).draw
```