danvk / dygraphs

Interactive visualizations of time series using JavaScript and the HTML canvas tag
http://dygraphs.com
Other
3.17k stars 606 forks source link

rollperiod alignment option #843

Open mathiasleroy opened 7 years ago

mathiasleroy commented 7 years ago

I found out that the rollPeriod is not centered like I thought.

In fact the rollPeriod corresponds the n days after any date. e.g. for n=7:

 x
[-------]

It would be useful to be able to change the alignment like a centered moving average

    x
[-------]

and even to shift the moving average window before the date

       x
[-------]

The problem is that if your last date is y and you select a rollPeriod of n, then the last date appearing on the chart will be y+n-1.

davRuser commented 6 years ago

Hi all,

I get an issue: my dygraph is non aligned with the time range:

ui.R

`sidebar <- dashboardSidebar(

sidebarMenu( menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")), menuItem("Widgets", icon = icon("th"), tabName = "widgets", badgeLabel = "new", badgeColor = "green") ) )

body <- dashboardBody( tabItems( tabItem(tabName = "dashboard", h2("Dashboard tab content"),

        sidebarPanel(

          fileInput("file1", "Choose CSV File",
                    multiple = TRUE,
                    accept = c("text/csv",
                               "text/comma-separated-values,text/plain",
                               ".csv")),

          tags$hr(),

          checkboxInput("header", "Header", TRUE),

          radioButtons("sep", "Separator",
                       choices = c(Comma = ",",
                                   Semicolon = ";",
                                   Tab = "\t"),
                       selected = ";"),

          radioButtons("quote", "Quote",
                       choices = c(None = "",
                                   "Double Quote" = '"',
                                   "Single Quote" = "'"),
                       selected = "")

),

dygraphOutput("dygraph",width = "50%", height = "300px"),

tabPanel('Display length',DT::dataTableOutput('dt'))

),

tabItem(tabName = "widgets",
        h2("Widgets tab content")
)

) )

dashboardPage( dashboardHeader(title = "Simple tabs"), sidebar, body )`

server.R

`server <- function(input, output) {

require(input$file1)

df <- reactive({ inFile <- input$file1 if (is.null(inFile)) return(NULL) df0 <- read.csv(inFile$datapath, header = input$header, sep = input$sep, quote = input$quote, stringsAsFactors = T) return(df0) })

df2 <- reactive({ if (is.null(input$file1)) return(NULL)else{ DataCleaning(df())} })

graphe <- reactive({ if (is.null(input$file1)) return(NULL)else{ TauxDef(df2()[[9]],df2()[[10]])} })

output$dygraph <- renderDygraph({ if (is.null(input$file1)) return(NULL)else{ MyGraph<-graphe() dyRangeSelector(dygraph(MyGraph, main = "Taux de defaut"))}

  })

output$dt <- DT::renderDataTable( DT::datatable(df(), options = list(pageLength = 10,scrollX = TRUE)) )

}`

capture

przmv commented 6 years ago

@davRuser it's better to report your issue in RStudio/dygraphs repo.