Comments (2)
Hello Simon,
You have to use some JavaScript in tooltip's formatter, here's an example:
library(dplyr)
library(tidyr)
library(apexcharter)
my_data <- mtcars %>%
select(mpg, qsec) %>%
add_rownames("car") %>%
mutate(diff_mpg = round(mpg - lag(mpg), 1), diff_qsec = round(qsec - lag(qsec), 1)) %>%
select(car, diff_mpg, diff_qsec) %>%
gather(var, value, -car)
my_chart <- apex(my_data, type = "bar", aes(car, value, fill = var)) %>%
ax_plotOptions(bar = bar_opts(
horizontal = FALSE,
endingShape = "flat",
columnWidth = "70%",
dataLabels = list(
position = "top"
))
)
# Color value
my_chart %>%
ax_tooltip(
y = list(
formatter = JS(
"function(value) {",
"var color = value >= 0 ? 'forestgreen' : 'firebrick';",
"return '<span style=\"font-weight: 700; color:' + color + ';\">' + value + '</span>';",
"}"
)
)
)
# Use an icon: first we need to add FontAwesome dependency
my_chart$dependencies <- htmltools::htmlDependencies(shiny::icon("home")) # add FontAwesome HTML dependency
my_chart %>%
ax_tooltip(
y = list(
formatter = JS(
"function(value) {",
# https://fontawesome.com/v4.7.0/icon/arrow-down
"var icon_up = '<i class=\"fa fa-arrow-up\" aria-hidden=\"true\"></i>';",
"var icon_down = '<i class=\"fa fa-arrow-down\" aria-hidden=\"true\"></i>';",
"var icon = value >= 0 ? icon_up : icon_down;",
"return value + ' ' + icon;",
"}"
)
)
)
Of course you can combine the two or color the icon.
Victor
from apexcharter.
thanks a lot. Works perfect.
from apexcharter.
Related Issues (20)
- [feature request] set_input_hover for capturing mouseover events HOT 1
- Wrong x-axis labels and ticks with `type="numeric"` HOT 12
- [Feature Request] Text annotation with add_text HOT 2
- Adding Confidence Intervals HOT 4
- Creating box plot with apexcharter HOT 2
- facet not working on shinyapps HOT 3
- Brush does not work HOT 3
- Combining facets with annotations HOT 1
- Mixed/Combo charts when using apex() function to create series
- Stacked Bar Chart by Week Ending Date - x-axis labels HOT 3
- Colour mis-match on line markers for more than 10 series HOT 1
- No shared tooltip HOT 4
- Thrid y axis HOT 2
- Change to new cran checks badge URL HOT 1
- Feature request: New chart type - box plots HOT 5
- Adding Icons to the Labels in a Legend HOT 4
- Format numbers in spark_box's tooltip HOT 2
- ax_forecast_data_points() seems to be missing HOT 2
- Remove Time Gaps from Candlestick Chart HOT 2
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 apexcharter.