datastorm-open / rAmCharts

API for Amcharts
48 stars 17 forks source link

Bug with Latest version of rAmCharts #48

Closed debsush closed 8 years ago

debsush commented 8 years ago

In the latest version of rAmChart (post v1.1.3), data frame containing column headers with special character or numbers are not rendered. It worked fine in v1.1.3

Example , if I change the data frame column name from runExamples() and introduce a space " ", the chart does not render. Please help me resolve this bug in the package

 ## Data
    times <- as.POSIXct(seq(-60 * 60 * 24 * 50 + 1, 0, by = 3600), origin = Sys.time(), tz = 'UTC')
    times <- round(times,'hours')
    times <- data.frame(times)
    times$Mesure <- 1:length(times$times) + rep(cos(seq(-pi,pi,length.out = 100)), 12) * 500 + runif(length(times$times)) * 200
     colnames(times)[2]<-"20 Micron"
#     dummy1<<-times

    mycategoryBalloonDateFormat <- list(list(period = 'YYYY', format = 'YYYY'),
                                        list(period='MM', format = 'YYYY-MM'), 
                                        list(period = 'WW', format = 'YYYY-MM-DD'),
                                        list(period='DD', format = 'YYYY-MM-DD'), 
                                        list(period = 'hh', format = 'YYYY-MM-DD JJ:NN'),
                                        list(period='mm', format = 'YYYY-MM-DD JJ:NN'), 
                                        list(period = 'ss', format = 'YYYY-MM-DD JJ:NN:ss'),
                                        list(period='fff', format = 'YYYY-MM-DD JJ:NN:ss'))
    ## Plot
    graph<-pipeR::pipeline(
      amStockChart(dataDateFormat = 'YYYY-MM-DD JJ:NN:ss') ,
      addDataSet(pipeR::pipeline(
        dataSet(title = 'first data set', categoryField = 'times') ,
        setDataProvider(times,keepNA=FALSE),
        addFieldMapping(fromField = colnames(times)[2], toField = colnames(times)[2]))),
      addPanel(pipeR::pipeline(
        stockPanel(showCategoryAxis = TRUE, title = 'Value') ,
        addStockGraph(id = 'g1',connect=FALSE, valueField = colnames(times)[2], comparable = TRUE,periodValue = 'Average',type='column',
                      compareField = colnames(times)[2], balloonText = 'Value : <b>[[value]] Unit</b>', precision = 0,
                      compareGraphBalloonText = '[[title]] =<b>[[value]]</b>'))),
      setChartScrollbarSettings(graph = 'g1'),
      setChartCursorSettings( valueBalloonsEnabled = TRUE, fullWidth = TRUE,
                              cursorAlpha = 0.1, valueLineBalloonEnabled = TRUE,
                              valueLineEnabled = TRUE, valueLineAlpha = 0.5,
                              categoryBalloonDateFormats = mycategoryBalloonDateFormat),
      setPeriodSelector(pipeR::pipeline( periodSelector( position = 'bottom' ,inputFieldsEnabled=FALSE) ,
                                         addPeriod( period = 'DD', selected = TRUE, count = 1, label = '1 day') ,
                                         addPeriod( period = 'WW', count = 1, label = '1 week' ) ,
                                         addPeriod( period = 'MAX', label = 'All' ))),
      setCategoryAxesSettings(parseDates = TRUE, minPeriod = '1hh',
                              groupToPeriods = c('hh','3hh', '12hh','1DD'),maxSeries = 50),
      setPanelsSettings(recalculateToPercents = 'never', creditsPosition='top-left')
    )
bthieurmel commented 8 years ago

You're right. It's fix on github. But we have to keep in mind that R don't like space and number (at the beginning) on colnames. So the best practice is to don't use this and perhaps use some label or title property on the library

debsush commented 8 years ago

Sure. Will do. Thank you for the fix.