rCharts Highcharts更改xAxis标签

时间:2014-04-30 13:36:47

标签: date highcharts axis-labels rcharts

所以我试图用x轴读数作为我的data.frames中的日期。 然而,它仍然是0,1,2,3,4,5,....,20,而不是4月1日,4月2日... 4月29日

 data.setup<-function(data,loc='yahoo',start.date=Sys.Date()-months(1),
                                      end.date=Sys.Date()) {
  getSymbols(data,src=loc)
  x<-as.data.frame(window(get(data),
            start=as.character(start.date),
            end=as.character(end.date)))
  x$dates<-row.names(x)
  colnames(x)<-c('Open','High','Low','Close','Volume','Adjusted','Dates')
  x<-x[c(7,1,2,3,4,5,6)]
  return(return(x))
}

data<-data.setup('AAPL',start.date=Sys.Date()-months(1))  
h1<-Highcharts$new()
h1$chart(type='line')
h1$xAxis(category=data$Dates,id='dates')
h1$series(data=data$Low,name='Low',xAxis='dates')

1 个答案:

答案 0 :(得分:1)

不是category而是categories

# data
df <- data.frame(x = 1:10, y = rnorm(10), s = rnorm(10), z = letters[1:10])

# create plot object
p <- hPlot(y ~ x, data = df, size = "s", type = "line")

# set axis
p$xAxis(categories = as.character(seq(Sys.Date(), by = 1, length.out = 10)))

# show
p