# Load packages and initialize data here
library(flexdashboard)
library(chartjs)

Row 1

Bar Chart

chartjs() %>%
  cjsOptions(responsive = FALSE, maintainAspectRatio = FALSE) %>% 
  cjsBar(labels = LETTERS[1:10]) %>%
  cjsSeries(data = c(abs(c(rnorm(8))), NA, 0.5), label = "Series 1") %>%
  cjsSeries(data = abs(c(rnorm(10))), label = "Series 2") %>%
  cjsSeries(data = abs(c(rnorm(10))), label = "Series 3") %>% 
  cjsLegend()

Horizontal Bar Chart

customColors = list(border = rep("#000000", 3),
                    background = RColorBrewer::brewer.pal(6, "Paired")[c(3, 5, 1)],
                    hover = list(border =  rep("rgba(255,255,255,1)", 3),
                                 background = RColorBrewer::brewer.pal(6, "Paired")[c(4, 6, 2)]))

chartjs(palette = customColors) %>%
  cjsOptions(responsive = FALSE, maintainAspectRatio = FALSE) %>% 
  cjsHorizontalBar(labels = LETTERS[1:10]) %>%
  cjsEditScale(axis = "x", scale = 1, ticks = list(beginAtZero = TRUE)) %>% 
  cjsSeries(data = 1:10, label = "Series 1") %>%
  cjsSeries(data = seq(10, 1, -1), label = "Series 2") %>%
  cjsSeries(data = rep(5, 10), label = "Series 3") %>% 
  cjsLegend()

Row 2

Pie Chart

chartjs(palette = "Set3") %>%
  cjsOptions(responsive = FALSE, maintainAspectRatio = FALSE) %>% 
  cjsPie(labels = LETTERS[1:4]) %>%
  cjsSeries(data = abs(c(rnorm(4)))) %>% 
  cjsLegend()

Line Chart

chartjs(palette = "BrBG") %>%
  cjsOptions(responsive = FALSE, maintainAspectRatio = FALSE) %>% 
  cjsLine(labels = LETTERS[1:10]) %>%
  cjsSeries(data = c(abs(c(rnorm(8))), NA, 0.5), label = "Series 1") %>%
  cjsSeries(data = abs(c(rnorm(10))), label = "Series 2") %>%
  cjsSeries(data = abs(c(rnorm(10))), label = "Series 3") %>% 
  cjsLegend()


Tutuchan/chartjs documentation built on May 9, 2019, 5:16 p.m.