danvk / dygraphs

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

second y-axis unexpectedly flipping (more negative toward the top of the graph) #653

Open QuickQuant opened 9 years ago

QuickQuant commented 9 years ago

When graphing this data set that contains a spike, the y-axis inverts. If I switch the y axis with the y2 axis, it works as expected. If I graph a subset of the data that does not contain the spike, it works as expected (although that changes the "minimum" of the data, which changes the slider settings, which changes the axis settings, but only in magnitude; the min is always less than the max anyway, so scale shouldn't matter.) good dychart bad dychart Here's some relevant code in case something jumps out that I'm doing wrong... I can include more code and the raw data set if nobody thinks this is already a known issue.

this is buggy:

output$DXGraph <- renderDygraph({ df1 <- DXDataSubset() if (length(df1) > 1){ DXxts <- xts(df1, order.by = as.POSIXlt(as.character(unlist(df1[, 'utc_datetime']))), tz = "UTC") dygraph(DXxts[,c('premium','mid.x')], main = "Premium and Mid.x of DX data") %>% dyAxis("y", label = "mid.x", valueRange = c(input$YAxisSlider[1],input$YAxisSlider[2])) %>% dySeries('premium',axis = 'y2') %>% dyOptions(connectSeparatedPoints = FALSE) %>% dyOptions(animatedZooms = TRUE) %>% dyRangeSelector() }

this works:

output$DXGraph <- renderDygraph({ df1 <- DXDataSubset() if (length(df1) > 1){ DXxts <- xts(df1, order.by = as.POSIXlt(as.character(unlist(df1[, 'utc_datetime']))), tz = "UTC") dygraph(DXxts[,c('premium','mid.x')], main = "Premium and Mid.x of DX data") %>% dyAxis("y", label = "premium", valueRange = c(input$YAxisSlider[1],input$YAxisSlider[2])) %>% ###only change: changed premium <--> mid.x from the line below dySeries('mid.x',axis = 'y2') %>% dyOptions(connectSeparatedPoints = FALSE) %>% dyOptions(animatedZooms = TRUE) %>% dyRangeSelector() } })

danvk commented 9 years ago

If the valueRange is inverted (e.g. [100, 0] instead of [0, 100]), then the axis will appear upside-down. This is by design. Is this what you're running into?

QuickQuant commented 9 years ago

no, I was graphing a range of data from june through august, and merely by extending the range from june-august 14th to june through august 15th it flipped the axis. so the only difference was the data input subset as controlled by the shiny UI. It's worth noting that the 15th had negative values for some of the points, unlike everywhere else I can include some screenshots of data if you want On Aug 26, 2015 3:56 PM, "Dan Vanderkam" notifications@github.com wrote:

If the valueRange is inverted (e.g. [100, 0] instead of [0, 100]), then the axis will appear upside-down. This is by design. Is this what you're running into?

— Reply to this email directly or view it on GitHub https://github.com/danvk/dygraphs/issues/653#issuecomment-135168086.