Reputation: 1372
I want series name at the end of line series with color of series. I am looking for similar output present here - Highcharts Line Chart, display series name at the end of line series
I am able to include series name at the end of line series but fails to show it as color of series. This is the solution I am unable to include it in highcharter in R as it has both single and double quotes. R is unable to recognise it.
formatter: function() {
return '<span style="color:'+this.series.color+'">'+this.series.name+'</span>';
}
My Code is shown below -
highchart() %>%
hc_chart(type = "spline") %>%
hc_title(text = "Demo",
align = "center",
style = list(
fontFamily = "Roboto",
color = "#444",
fontWeight = "bold"
)) %>%
hc_xAxis(categories = iris$Species) %>%
hc_yAxis(labels = list(format = "{value}M")) %>%
hc_add_series(name = "Sepal.Length",
data = iris$Sepal.Length,
marker = list(enabled= FALSE),
color='red',
lineWidth=4,
lineColor='red') %>%
hc_add_series(name = "Petal.Length",
data = iris$Petal.Length,
marker = list(enabled= FALSE),
type = "area",
color='#f6f3ef',
lineWidth=3,
lineColor='#e4dcd2',
dashStyle = "ShortDot") %>%
hc_plotOptions(
series = list(
dataLabels = list(
enabled = TRUE,
allowOverlap = TRUE,
align = 'center',
verticalAlign = 'bottom',
style = list(fontSize = '14px', color = '#666'),
formatter = JS("
function() {
if (this.point.x == this.series.data.length - 1) {
return this.series.name;
}
return '';
}")))) %>%
hc_tooltip(pointFormat="{point.series.name}: €<b>{point.y:,.2f}M</b><br/>", shared= TRUE) %>%
hc_add_theme(anacap_theme(palettes = "lightbluegolden")) %>%
hc_exporting(enabled = TRUE)
Upvotes: 0
Views: 671
Reputation: 2234
Can't you escape the double quotes like that since you want to keep double quotes in the markup?
formatter: function() {
return '<span style=\"color:' + this.series.color + '\">' + this.series.name + '</span>';
}
Upvotes: 1