ramnathv / rCharts

Interactive JS Charts from R
http://rcharts.io
Other
1.19k stars 655 forks source link

tooltip over lap when including more then one nPlot in a simgle page #302

Open morankor opened 11 years ago

morankor commented 11 years ago

Hi All,

I am trying to include two different nvd3 graphs on a single page (shiny app) using rCharts.

I need to customize the tooltips for one of them so I use the following settings:

PCTcrimeplot$chart(tooltipContent = "#! function(key, x, y, e, graph) {  return '<h3>' + key + '</h3>' +    '<p>' + e.point.msg + '</p>'}!#")

for some reason , the tooltip on another chart ,a regular "lineChart" also stop working ,

I am attaching an example of the first chart maybe there is something else wrong there:

the data frame:

        date           series1                 series2  period     mean
1 2013-11-01      2.244983           1.0842331      1    2.049811
2 2013-11-02      2.172690           0.9480411      1    2.049811
3 2013-11-03      2.015747           0.9114889      1    2.049811
4 2013-11-04      2.064868           1.0351437      2    3.049811
5 2013-11-05      1.893775           1.0457806      2    3.049811
6 2013-11-06      1.906803           0.9327594      2    3.049811

and the graph generating function:

get_rpm_overall_chart<-cmpfun(function(df,chart_name){
  require('rCharts')
  #for normal tick placement on graph:

  df<-df[,c("date","series1","series2","mean")]
  df[,2:4]<-round(df[,2:4],2)
  ecm <- reshape2::melt(df, id = 'date')
  ecm$date<-as.Date(ecm$date)

  p7 <- nPlot(value ~ date, group = 'variable', data = ecm, type = 'lineChart')
  p7$xAxis( tickFormat="#!function(d) {return d3.time.format('%d %b %Y')(new Date( d ));}!#" )

  return(p7)  

})

The graph looks great , but the tooltip is not working....

Please Help!

Thanks!

MorKo

morankor commented 11 years ago

here are the R code to generate the dataframe:

df<-as.data.frame(cbind(c(as.character(seq(as.Date('2013-11-01'),as.Date('2013-11-10'),by="days"))),c(2.244,2.17,2.08,3.6,1.89),c(1:10+rnorm(10,0.5))))
names(df)<-c("date","series1","series2")