Comments (4)
Hi,
Can you provide a complete example please ? I'll look into it.
Victor
from apexcharter.
Thank you for your help. Here is the complete code:
I used parts of your apex
function to create the series before the API with the apexchart
function. At least for me, this would be a great function worth integrating into the package.
create_apex_series_original <- function(data, mapping, type = "column", ...,
auto_update = TRUE,
synchronize = NULL,
serie_name = NULL,
width = NULL,
height = NULL,
elementId = NULL) {
rename_aes_heatmap <- utils::getFromNamespace("rename_aes_heatmap", "apexcharter")
is_sized <- utils::getFromNamespace("is_sized", "apexcharter")
correct_type <- utils::getFromNamespace("correct_type", "apexcharter")
make_series <- utils::getFromNamespace("make_series", "apexcharter")
choose_config <- utils::getFromNamespace("choose_config", "apexcharter")
rename_aes_heatmap <- utils::getFromNamespace("rename_aes_heatmap", "apexcharter")
rename_aes <- utils::getFromNamespace("rename_aes", "apexcharter")
type <- match.arg(
arg = type,
choices = c(
"column", "bar",
"line", "spline", "step",
"area", "area-spline", "area-step",
"pie", "donut",
"radialBar",
"radar",
"polarArea",
"scatter", "bubble",
"heatmap",
"treemap",
"timeline",
"candlestick"
)
)
data <- as.data.frame(data)
if (identical(type, "heatmap")) {
mapping <- rename_aes_heatmap(mapping)
} else {
mapping <- rename_aes(mapping)
}
if (identical(type, "scatter") & is_sized(mapping)) {
type <- "bubble"
}
mapdata <- lapply(mapping, rlang::eval_tidy, data = data)
if (is.null(mapdata$y) & !type %in% c("candlestick", "timeline", "heatmap")) {
mapdata <- compute_count(mapdata)
}
if (type %in% c("pie", "donut", "radialBar", "polarArea")) {
series <- list(mapdata$y)
} else {
series <- make_series(mapdata, mapping, type, serie_name)
}
return(series)
}
y <- c(0,0,0,0,0)
x <- c(-1, 0.3, 0, -0.1, 1)
z <- rep(10,5)
group <- c("a", "b", "c", "d", "e")
mapdata <- data.frame(x=x, y=y, group=group, z=z)
mapping = apexcharter::aes(x,
y,
group = group,
size = z,
label = group
)
series <- create_apex_series_original(mapdata, mapping= mapping, type = "scatter", force_datetime_names = FALSE)
series
fig <- apexcharter::apexchart(ax_opts = list(
chart = list(
type = "bubble",
# fontFamily = 'Nunito',
height = 35,
width = 200,
sparkline= list(
enabled = TRUE
)
),
stroke=list(
show=FALSE
),
dataLabels = list(
enabled = FALSE
),
series = series,
tooltip = list(
x=list(
show=FALSE
),
shared = FALSE
),
colors = c("#8089f5", "#0beaab","#fa6c89", "#ffc219", "#4199f8"),
xaxis = list(
min=-1.1,
max=1.1,
type='numeric',
title = list(
style= list(fontSize= '13px',
fontWeight= 'bold'
)
),
labels = list(style= list(fontSize= '11px'
)),
tooltip= list(
enabled = FALSE
)
),
fill=list(
type="solid",
opacity=1
),
markers = list(
strokeWidth = 0,
radius=0,
fillOpacity= 0.9
),
# background
annotations=list(
position= "back",
xaxis=list(
list(
label=list(
text= " "
),
x= -1.1,
x2= 0,
fillColor= "#dc3545",
opacity=0.2
),
list(
label=list(
text= " "
),
x= 0,
x2= 1.1,
fillColor= "#28a745",
opacity=0.2
)
)
),
yaxis = list(
min=-0.2,
max=0.2,
title = list(
style= list(fontSize= '13px',
fontWeight= 'bold'
)
),
labels = list(style= list(fontSize= '11px'
)
)
)
))
fig$height <- 35
fig <- fig %>%
apexcharter::ax_tooltip(custom = apexcharter::JS(paste(
"function({ series, seriesIndex, dataPointIndex, w }) {",
"console.log(w); return (",
"'<div>' +",
# "'<div class = \"apexcharts-tooltip-title\">' +",
# "w.config.series[seriesIndex].data[dataPointIndex].label",
# "+ '</div>' +",
# "'<div style = \"padding: 5px;\">' +",
# "'<div class = \"apexcharts-tooltip-series-group\">' +",
# "'<span class = \"apexcharts-tooltip-marker\" style=\"background-color: rgb(57, 175, 209);\">' +",
# "'</span>' +",
"'<div class = \"apexcharts-tooltip-text\">' +",
"'<div class = \"apexcharts-tooltip-y-group\">' +",
"'<span class = \"apexcharts-tooltip-text-label\">' +",
# "w.config.series[seriesIndex].data[dataPointIndex].label + ':' +",
"'</span>' +",
"'<span class = \"apexcharts-tooltip-text-value\">' +",
"Math.round(w.config.series[seriesIndex].data[dataPointIndex].x * 100, 2) + ' %' +",
"'</span>' +",
# "'</div>' +",
# "'</div>' +",
"'</div>' +",
"'</div>' +",
"'</div>'",
");",
"}", sep = "\n"
)))
fig
from apexcharter.
Thanks for the example. You can customize tooltip with formatters function:
ax_tooltip(
x = list(show = FALSE),
y = list(
formatter = JS(
"function(value, {series, seriesIndex, dataPointIndex, w}) {",
"return Math.round(w.config.series[seriesIndex].data[dataPointIndex].x * 100, 2) + ' %';",
"}"
),
title = list(
formatter = JS(
"function(value) {return null;}"
)
)
),
z = list(
formatter = JS(
"function(value) {return null;}"
)
)
)
Those function are intended to be used by apex()
, if you want to use the list
syntax, you can create series with lapply
and parse_df
, something like:
lapply(
X = unique(data$group),
FUN = function(x) {
d <- data[data$group == x, ]
list(name = x, data = parse_df(d, add_names = TRUE))
}
)
With apex()
, your example will look like:
y <- c(0, 0, 0, 0, 0)
x <- c(-1, 0.3, 0, -0.1, 1)
z <- rep(10,5)
group <- c("a", "b", "c", "d", "e")
data <- data.frame(x = x, y = y, group = group, z = z)
apex(data, aes(x, y, group = group, size = z), type = "bubble", height = 35) %>%
ax_chart(sparkline = list(enabled = TRUE)) %>%
ax_xaxis(min = -1.1, max = 1.1) %>%
ax_yaxis(min = -0.2, max = 0.2) %>%
ax_fill(type = "solid", opacity = 1) %>%
ax_annotations(
position= "back",
xaxis = list(
list(
x = -1.1,
x2 = 0,
fillColor = "#dc3545",
opacity = 0.2
),
list(
x = 0,
x2 = 1.1,
fillColor = "#28a745",
opacity = 0.2
)
)
) %>%
ax_tooltip(
x = list(show = FALSE),
y = list(
formatter = JS(
"function(value, {series, seriesIndex, dataPointIndex, w}) {",
"return Math.round(w.config.series[seriesIndex].data[dataPointIndex].x * 100, 2) + ' %';",
"}"
),
title = list(
formatter = JS(
"function(value) {return null;}"
)
)
),
z = list(
formatter = JS(
"function(value) {return null;}"
)
)
)
Victor
from apexcharter.
Hi Victor,
thanks a lot! This example with function(value, {series, seriesIndex, dataPointIndex, w}
helps a lot!
Best,
Tobias
from apexcharter.
Related Issues (20)
- Adding Icons or Color to the Tooltip 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
- [Feature request] - adding outliers and custom data points to a boxplot
- Synchronize Charts Example doesn't display both plots at the same time in Rstudio's plot panel. HOT 2
- Feature request: bring crosstalk functionality to connect apexchart with tables
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.