datastorm-open / rAmCharts

API for Amcharts
48 stars 16 forks source link

Setting Axis via minimum and maximum properties not working #77

Closed cegbuna closed 6 years ago

cegbuna commented 6 years ago

Hi,

Thanks again for this awesome charting package.

I'm currently having issues setting axis limits using the minimum and maximum propertis in serial charts. Am I missing something in the code below?

# fake data
df1 <- data.frame(Date = seq(Sys.Date()-365, Sys.Date(), 30), 
                  var1 = round(runif(13, 1000, 10000),0),
                  var2 = round(runif(13, 1000, 10000),0),
                  var3 = round(runif(13, 1000, 20000),0)

)

# Create value axis
valueAxis_ls <- list(
  valueAxis(id = "v1", min = 0, maximum = 50000, axisColor = "green", axisThickness = 2, axisAlpha = 1, color = "green", position = "left", title = "title 1", titleColor = "green", gridAlpha = 0.1),
  valueAxis(id = "v2", minorGridAlpha = 0, axisColor = "red", axisThickness = 2, axisAlpha = 1, color = "red", position = "right", title = "title2", titleColor = "red", gridAlpha = 0.1),
  valueAxis(id = "v3", minorGridAlpha = 0, axisColor = "blue", axisThickness = 2, axisAlpha = 1, color = "blue", position = "left", offset = 80, title = "title3", titleColor = "blue", gridAlpha = 0.1)
)

# Create graph
graphs_ls <- list(
  graph(valueAxis = "v1", lineColor = "green", bullet = "none", bulletBorderThickness = 1, lineThickness = 2,
        hideBulletsCount = 30, title = "title 1", valueField = "var1", fillAlphas = 0),
  graph(valueAxis = "v2", lineColor = "red", bullet = "none", bulletBorderThickness = 1, lineThickness = 2, 
        hideBulletsCount = 30, title = "title 2", valueField = "var2", fillAlphas = 0), 
  graph(valueAxis = "v3", lineColor = "blue", bullet = "none", bulletBorderThickness = 1, lineThickness = 2, 
        hideBulletsCount = 30, title = "title 3", valueField = "var3", fillAlphas = 0)
)

chartCursor_obj <- chartCursor(oneBallOnly = TRUE)
chartScrollbar_obj <- chartScrollbar(updateOnReleaseOnly = FALSE)

amSerialChart(dataProvider = df1, categoryField = 'Date', synchronizeGrid = TRUE, graphs = graphs_ls, valueAxes = valueAxis_ls,
              chartCursor = chartCursor_obj, marginTop = 5, marginLeft = 5,
              autoMarginOffset = 10, mouseWheelScrollEnabled = TRUE, mouseWheelZoomEnabled = TRUE) %>>%
  addTitle(text = "Chart Title", bold = TRUE) %>>%
  setLegend(equalWidths = FALSE, markerSize = 5, markerBorderThickness = 5, rollOverGraphAlpha = 0.1,
            position = 'top', valueAlign = 'left', valueWidth = 1000, verticalGap = 0,
            markerType = "line", align = "left", useGraphSettings = TRUE) 

Thanks.

bthieurmel commented 6 years ago

It seems you have to set synchronizeGrid = FALSE

cegbuna commented 6 years ago

Thanks for the quick response. I did set synchronizeGrid = FALSE but the chart is still not behaving as expected. Although the maximum axis limits changes the chart doesn't display the limits I set. The minimum property doesn't work at all.

Thanks

bthieurmel commented 6 years ago

I forgot this : use minimum = 0 rather than min = 0

cegbuna commented 6 years ago

I did catch that and adjusted the minimum property, but it still doesn't work. I set minimum = 500 but the chart's minimum xAxis is still at 0.

Thanks

bthieurmel commented 6 years ago

amCharts can change minimum or maximum to have full axis grid. You can try to use strictMinMax = TRUE to force the limit.

cegbuna commented 6 years ago

That did the trick, thanks for your response.

Is there a way to remove the gridlines in the plot area? I did set the gridAlpha = 0 for the v1, v2 and v3 axis. This worked but the top axis line disappeared. I would like to still have a box around the chart but with no gridlines in the plot area.

Thanks again.

bthieurmel commented 6 years ago

amCharts have a lot of options. If you don't know this site, you can play with options and retrieve code :

https://live.amcharts.com/