Comments (13)
I do not know Java. Is there possibility to create composite bar in R ?
from sparkline.
@tazik, I'll make this much better.
With existing sparkline
using onRender
With the newest Github version of htmlwidgets
,
devtools::install_github("ramnathv/htmlwidgets")
we get onRender
, so we could do something like this.
# hack to provide composite charts
# https://github.com/htmlwidgets/sparkline/issues/13
library(htmlwidgets)
library(sparkline)
onRender(
sparkline(
c(5,4,5,-2,0,3),
type='bar',
barColor="#aaf",
chartRangeMin=-5,
chartRangeMax=10
),
"
function(el,x){
$(el).sparkline(
[4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7],
{
composite: true,
fillColor: false,
lineColor: 'red',
chartRangeMin: -5,
chartRangeMax: 10
}
)
}
"
)
With hack in experimental forked branch
# here is another way if we use experimental forked branch
# but I still don't like this way of accomplishing
# I think a addComposite function would be better
# first install from Github
#devtools::install_github("timelyportfolio/sparkline@update/sparkline")
library(sparkline)
library(htmltools)
sl1 <- sparkline(
c(5,4,5,-2,0,3),
type='bar',
barColor="#aaf",
chartRangeMin=-5,
chartRangeMax=10,
# set an id that will make it easier to refer
# in the next sparkline
elementId="sparkline-for-composite"
)
sl2 <- sparkline(
c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7),
type="line",
fillColor = FALSE,
lineColor ='red',
chartRangeMin = -5,
chartRangeMax = 10,
# will need to set composite = TRUE
composite = TRUE,
# and set renderSelector to the id we set in the previous sparkline
renderSelector = "#sparkline-for-composite"
)
browsable(tagList(sl1,sl2))
With helper function and experimental forked branch
# first install from Github
#devtools::install_github("timelyportfolio/sparkline@update/sparkline")
sl1 <- sparkline(
c(5,4,5,-2,0,3),
type='bar',
barColor="#aaf",
chartRangeMin=-5,
chartRangeMax=10
)
# try to make a function to add a composite to an existing sparkline
# of course if we did this for real, we would make much more robust
# also, I added some JavaScript code to handle composites
addComposite <- function(sparkline=NULL, ...){
stopifnot(!is.null(sparkline),inherits(sparkline,"sparkline"))
sparkline_options <- list(...)
sparkline_options$options$composite <- TRUE
sparkline$x$composites[[length(sparkline$x$composites)+1]] <- sparkline_options
return(sparkline)
}
addComposite(
sl1,
values=c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7),
options = list(
type="line",
fillColor = FALSE,
lineColor ='red',
chartRangeMin = -5,
chartRangeMax = 10
)
)
from sparkline.
Can you point me to the equivalent javascript code?
from sparkline.
@ramnathv
I'd like to do to something like this:
$('#sparkline').sparkline([5, 4, 5, -2, 0, 3], { type: 'bar', barColor: '#aaf' }); $('#sparkline').sparkline([4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7], { composite: true, fillColor: false, lineColor: 'red' });
with that kind of code:
{"x":{"values":[0,12,22,38,20,32,32,21],"options":{"type":"bar", "height":20,"width":60},"width":60,"height":20},"evals":[]} {"x":{"values":[0,12,22,38,20,32,32,21],"options":{"composite":true, "type":"line", "height":20,"width":60},"width":60,"height":20},"evals":[]}
but I do not understand syntax. Can you help me?
from sparkline.
I get it now. This package does not support composite plots currently, but I have a pending PR that will make that possible. I don't have an ETA on when those changes would get merged in, but when I do merge them in, I will leave a note for you here.
from sparkline.
Thanks for response. I can't wait you drop this feature. It'll be very useful for me!
from sparkline.
Did this get merged?
from sparkline.
Hm... isn't there any possibility to do in the meantime?
from sparkline.
@ramnathv, I would love to see this. Will push forward with this unless you tell me no :) I know yours will be way more elegant though.
from sparkline.
cc @diegocgaona, if interested in potential new sparkline functionality.
from sparkline.
As I work through this, I think a composite function addComposite
like this would be more flexible.
# first install from Github
#devtools::install_github("timelyportfolio/sparkline@update/sparkline")
sl1 <- sparkline(
c(5,4,5,-2,0,3),
type='bar',
barColor="#aaf",
chartRangeMin=-5,
chartRangeMax=10,
# set an id that will make it easier to refer
# in the next sparkline
elementId="sparkline-for-composite"
)
sl2 <- sparkline(
c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7),
type="line",
fillColor = FALSE,
lineColor ='red',
chartRangeMin = -5,
chartRangeMax = 10,
# will need to set composite = TRUE
composite = TRUE,
# and set renderSelector to the id we set in the previous sparkline
renderSelector = "#sparkline-for-composite"
)
# try to make a function to add a composite to an existing sparkline
addComposite <- function(sparkline=NULL, sparklineToAdd=NULL, ...){
stopifnot(
!is.null(sparkline),
inherits(sparkline,"sparkline")
)
sparkline_options <- list()
# if a sparkline is provided to add
# then get its values and options
if(!is.null(sparklineToAdd)) {
sparkline_options <- list(
values = sparklineToAdd$x$values,
options = sparklineToAdd$x$options
)
}
# if ... are provided
# then use these for values and options
if(length(list(...)) > 0) {
sparkline_options <- modifyList(sparkline_options,list(...))
}
sparkline_options$options$composite <- TRUE
sparkline$x$composites[[length(sparkline$x$composites)+1]] <- sparkline_options
return(sparkline)
}
# add sparkline as a composite
addComposite(sl1, sl2)
# add values and options as a composite
addComposite(
sl1,
values=c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7),
options = list(
type="line",
fillColor = FALSE,
lineColor ='red',
chartRangeMin = -5,
chartRangeMax = 10
)
)
# add combination of sparkline and options as a composite
addComposite(
sl1,
sl2,
options = list(
type="box"
)
)
from sparkline.
Hi @timelyportfolio , sorry for this dumb question, but how can I install your dev version to test?
thanks!
EDIT: Sorry for may lack of attention, I was in my work and didn't read the code, now I see the fork to install
Now I tested it, and I loved it! When you finish the update I will modify my project to use it in several graphs.
One doubt, how I set the size of the spark? I tried some like this (as I did in the without composite) but the size don't change
sl1 <- sparkline(
c(5,4,5,-2,0,3),
type='bar',
barColor="#aaf",
chartRangeMin=-5,
chartRangeMax=10,
width = 200, # the normal argument to set the width
height = 32, # the normal argument to set the heigth
# set an id that will make it easier to refer
# in the next sparkline
elementId="sparkline-for-composite"
)
sl2 <- sparkline(
c(4,1,5,7,9,9,8,7,6,6,4,7,8,4,3,2,2,5,6,7),
type="line",
fillColor = FALSE,
lineColor ='red',
chartRangeMin = -5,
chartRangeMax = 10,
width = 200,
height = 32,
# will need to set composite = TRUE
composite = TRUE,
# and set renderSelector to the id we set in the previous sparkline
renderSelector = "#sparkline-for-composite"
)
# add combination of sparkline and options as a composite
addComposite(
sl1,
sl2,
options = list(
type="line",
width=200, # I tried with this line and without, but I had the same result, the default size.
heigth=32 # I tried with this line and without, but I had the same result, the default size.
)
)
Thanks!!
from sparkline.
I will close this for now. Please reopen if not addressed. I will open a separate issue for composites of different types no longer lining up.
from sparkline.
Related Issues (20)
- Additional tooltip info (like date, or values from a x axis) HOT 13
- Add package to CRAN HOT 9
- Add helper function for as.character(as.tags(sparkline())) HOT 1
- Add helper functions to add sparkline dependencies
- Add formattable to suggests HOT 1
- Preface sparkline helpers and functions with spk
- Create vignette to show sparklines with other htmlwidgets HOT 9
- Improve/chage default colors
- Use option colorMap with sparkline HOT 2
- Add x values to sparkline?
- Sparklines only appear on first page of DT table HOT 4
- Fixing sparkline columns with null values HOT 1
- Invalid comparison operator in dependency: >= HOT 1
- Creating Stacked Bar Charts HOT 3
- stacked bar chart HOT 1
- Unavailable plot options - Boxplots with minValue and maxValue HOT 3
- Passing values to tooltipValueLookups
- High Severity Security Vulnerability Detected by Github
- Sparklines fail to render in tableHTML
- Passing Pre-Computed Values to Boxplot Renders Incorrect Chart HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sparkline.