When you point to a point belonging to "Values ​​1" - the date is correctly displayed (Figure 1) Values ​​1. Displayed correctly. And if you hover on a point belonging to "Values ​​2" - the date is not displayed. (picture 2) Values ​​2. Displayed without a date. How to make to output?

hc <- highchart() %>% hc_add_series( name = 'Значения 1', data = df1, hcaes(x= Date, y = Value), type = 'line') %>% hc_add_series( name = 'Значения 2', data = df2, hcaes(x= Date, y = Value), type = 'scatter') %>% hc_chart(zoomType = 'xy')%>% hc_xAxis(tickmarkPlacement = "on", type = 'datetime', labels = list(format= "{value:%d-%m-%Y}" )) %>% hc_tooltip(valueDecimals = 2, xDateFormat = "%d-%m-%Y", headerFormat = '<b>{series.name}</b><br>', pointFormat = "Дата: <b>{point.key}</b><br>Толщина: <b>{point.y} [нм]</b>" ) hc 

Sample df1 data:

  Date Value 1 2017-11-20 539.62 2 2017-11-27 540.49 

Sample df2 data:

  Date Value 1 2017-11-20 542.5 2 2017-11-20 543 3 2017-11-27 540 3 2017-11-27 544.1 
  • one
    {point.key} on {point.x} did not try to change? - teran

1 answer 1

point.key need to replace point.x as indicated in the comment to the question. xDateFormat did not give the desired effect, so the date format was added directly to the description of the tooltip format. The result was: {point.x:%d-%m-%Y} .

Working code:

 library(data.table) library(highcharter) df1 <- fread(" N Date Value 1 2017-11-20 539.62 2 2017-11-27 540.49 ") df2 <- fread(" N Date Value 1 2017-11-20 542.5 2 2017-11-20 543 3 2017-11-27 540 3 2017-11-27 544.1 ") df1[, Date := as.Date(Date)] df2[, Date := as.Date(Date)] hc <- highchart() %>% hc_add_series( name = 'Значения 1', data = df1, hcaes(x= Date, y = Value), type = 'scatter', color = 'red') %>% hc_add_series( name = 'Значения 2', data = df2, hcaes(x= Date, y = Value), type = 'scatter', color = 'blue') %>% hc_chart(zoomType = 'xy')%>% hc_xAxis(tickmarkPlacement = "on", type = 'datetime', labels = list(format= "{value:%d-%m-%Y}" )) %>% hc_tooltip(valueDecimals = 2, xDateFormat = "%d-%m-%Y", headerFormat = '<b>{series.name}</b><br>', pointFormat = "Дата: <b>{point.x:%d-%m-%Y}</b><br>Толщина: <b>{point.y} [нм]</b>" ) hc 

enter image description here

  • Thank you very much, it all worked! - Andrei