Learn R Programming

rAmCharts (version 1.1.3)

initialize,AmChart-method: Create an AmChart

Description

Method for initializing any S4 class provided by the package.

Add subData for drilldrown

Usage

"initialize"(.Object, allLabels, arrows, axes, balloon, categoryAxis, categoryField, chartCursor, chartScrollbar, creditsPosition, dataProvider, graphs, graph, guides, legend, segmentsField, theme, titles, trendLines, type, valueAxes, valueAxis, ...)
amChart(allLabels, arrows, axes, balloon, categoryAxis, categoryField, chartCursor, chartScrollbar, creditsPosition, dataProvider, graph, graphs, guides, legend, segmentsField, theme, titles, trendLines, type, valueAxes, valueAxis, ...)
amAngularGaugeChart(arrows, titles, axes, ...)
amFunnelChart(dataProvider, marginLeft = 10, marginRight = 10, ...)
amRadarChart(allLabels, balloon, categoryField, creditsPosition, dataProvider, graphs, guides, legend, titles, valueAxes, ...)
amSerialChart(allLabels, balloon, categoryAxis, categoryField, chartCursor, chartScrollbar, creditsPosition, dataProvider, graphs, guides, legend, titles, trendLines, valueAxes, ...)
amPieChart(allLabels, balloon, creditsPosition, dataProvider, legend, titles, ...)
amGanttChart(categoryField, dataProvider, graph, segmentsField, valueAxis, ...)
amXYChart(creditsPosition, dataProvider, graphs, ...)
setAllLabels(.Object, allLabels)
"setAllLabels"(.Object, allLabels)
addLabel(.Object, label = NULL, ...)
"addLabel"(.Object, label = NULL, ...)
setArrows(.Object, arrows = NULL)
"setArrows"(.Object, arrows = NULL)
addArrow(.Object, arrow = NULL, ...)
"addArrow"(.Object, arrow = NULL, ...)
setAxes(.Object, axes, ...)
"setAxes"(.Object, axes)
addAxe(.Object, axe = NULL, ...)
"addAxe"(.Object, axe = NULL, ...)
addAxis(.Object, axis = NULL, ...)
"addAxis"(.Object, axis = NULL, ...)
"setBalloon"(.Object, amBalloon = NULL, ...)
setCategoryAxis(.Object, categoryAxis = NULL, ...)
"setCategoryAxis"(.Object, categoryAxis = NULL, ...)
setCategoryField(.Object, categoryField)
"setCategoryField"(.Object, categoryField)
setChartCursor(.Object, chartCursor = NULL, ...)
"setChartCursor"(.Object, chartCursor = NULL, ...)
setChartScrollbar(.Object, chartScrollbar = NULL, ...)
"setChartScrollbar"(.Object, chartScrollbar = NULL, ...)
setCreditsPosition(.Object, creditsPosition)
"setCreditsPosition"(.Object, creditsPosition)
setDataLoader(.Object, url, format, ...)
"setDataLoader"(.Object, url, format, ...)
"setDataProvider"(.Object, dataProvider, keepNA = TRUE)
setExport(.Object, enabled = TRUE, ...)
"setExport"(.Object, enabled = TRUE, ...)
setGraphs(.Object, graphs)
"setGraphs"(.Object, graphs)
addGraph(.Object, amGraph = NULL, ...)
"addGraph"(.Object, amGraph = NULL, ...)
"setGraph"(.Object, graph = NULL, ...)
setGuides(.Object, guides)
"setGuides"(.Object, guides)
"addGuide"(.Object, guide = NULL, ...)
setLegend(.Object, amLegend = NULL, ...)
"setLegend"(.Object, amLegend = NULL, ...)
setResponsive(.Object, enabled = TRUE, ...)
"setResponsive"(.Object, enabled = TRUE, ...)
addSegment(.Object, categoryIDs, sgts)
"addSegment"(.Object, categoryIDs, sgts)
addSubData(.Object, categoryIDs, data)
"addSubData"(.Object, categoryIDs, data)
setSubChartProperties(.Object, .subObject = NULL, ...)
"setSubChartProperties"(.Object, .subObject = NULL, ...)
setTitles(.Object, titles)
"setTitles"(.Object, titles)
addTitle(.Object, title = NULL, ...)
"addTitle"(.Object, title = NULL, ...)
setTrendLines(.Object, trendLines)
"setTrendLines"(.Object, trendLines)
addTrendLine(.Object, trendLine = NULL, ...)
"addTrendLine"(.Object, trendLine = NULL, ...)
"setType"(.Object, type)
setValueAxes(.Object, valueAxes)
"setValueAxes"(.Object, valueAxes)
addValueAxes(.Object, valueAxis = NULL, ...)
"addValueAxes"(.Object, valueAxis = NULL, ...)
addValueAxis(.Object, valueAxis = NULL, ...)
"addValueAxis"(.Object, valueAxis = NULL, ...)
"setValueAxis"(.Object, valueAxis = NULL, ...)

Arguments

.Object
AmChart.
allLabels
list of Label. Example of label object, with all possible properties: label(x = 20, y = 20, text = "this is label", align = "left", size = 12, color = "#CC0000", alpha = 1, rotation = 0, bold = TRUE, url = "http=//www.amcharts.com") Run api("Label") for more information.
arrows
list of GaugeArrow. Only valid for gauge charts. Run api("GaugeArrow") for more information.
axes
list of GaugeAxis properties. Only valid for gauge charts. Run api("GaugeAxis") for more information.
balloon
AmBalloon. Creates the balloons (tooltips) of the chart, It follows the mouse cursor when you roll-over the data items. The framework generates the instances automatically you only need to adjust the appearance to your needs. Run api("AmBalloon") for more information.
categoryAxis
CategoryAxis. Read-only. Chart creates category axis itself. If you want to change some properties, you should get this axis from the chart and set properties to this object.
categoryField
character. Category field name tells the chart the name of the field in your dataProvider object which will be used for category axis values.
chartCursor
ChartCursor. Cursor of a chart. Run api("ChartCursor") for more information.
chartScrollbar
ChartScrollbar. Chart's scrollbar. Run api("ChartScrollbar") for more information.
creditsPosition
character, specifying position of link to amCharts site. Allowed values are: "top-left", "top-right", "bottom-left" and "bottom-right".
dataProvider
data.frame, containing the data.
graphs
list of AmGraph. Creates the visualization of the data in following types: line, column, step line, smoothed line, olhc and candlestick.
graph
AmGraph. Only valid for Gantt charts. Gant chart actually creates multiple graphs (separate for each segment). Properties of this graph are passed to each of the created graphs - this allows you to control the look of segments. Run api("AmGraph") for more information.
guides
list of Guide. Instead of adding guides to the axes, you can push all of them to this array. In case guide has category or date defined, it will automatically will be assigned to the category axis. Otherwise to first value axis, unless you specify a different valueAxes for the guide. Run api("Guide") for more information.
legend
AmLegend. Legend of a chart. Run api("AmLegend") for more information.
segmentsField
character. Segments field in your data provider. Only valid for Gantt Charts.
theme
character. Theme of a chart. Config files of themes can be found in amcharts/themes/ folder. See http://www.amcharts.com/tutorials/working-with-themes/.
titles
list of Title. Run api("Title") for more information.
trendLines
list of TrendLine objects added to a chart. You can add trend lines to a chart using this list or access already existing trend lines.
type
character. Possible types are: "serial", "pie", "radar", "xy", "radar", "funnel", "gauge", "stock". See details about using argument type. (type map is in development).
valueAxes
list of ValueAxis. Chart creates one value axis automatically, so if you need only one value axis, you don't need to create it. Run api("ValueAxis") for more information.
valueAxis
ValueAxis. Only valid for Gantt Charts. Set it's type to "date" if your data is date or time based.
...
In case of constructor new("AmChart") or amChart() Dots represent other properties to set to the AmChart object. See http://docs.amcharts.com/3/javascriptstockchart/AmChart. In case of setters, dots represent properties of the object to add. See examples.
marginLeft
character, left margin of the chart.
marginRight
character, right margin of the chart.
label
(optional) Label. Argument of method addLabel.
arrow
(optional) GaugeArrow. Argument of method addArrow.
axe
(optional) GaugeAxis. Argument of deprecated method addAxe.
axis
(optional) GaugeAxis. same as axe.
amBalloon
AmBalloon, argument of method 'setBalloon'.
url
character.
format
character.
keepNA
object of class logical, default TRUE. Indicates if NULL values have to be kept or ignored.
enabled
logical, default TRUE. Should the export button be shown ?
amGraph
(optional) AmGraph.
guide
(optional) Guide. Argument of method addGuide.
amLegend
(optional) AmLegend.
categoryIDs
numeric, see details.
sgts
data.frame ( or list of data.frame for multiple add ).
data
data.frame. Data to draw at the second level, after clicking on the column.
.subObject
AmChart.
title
(optional) Title, argument of method addTitle.
trendLine
(optional) TrendLine. Argument of method addTrendLine.

Value

(updated) AmChart with given properties.

Functions

  • amChart:
  • amAngularGaugeChart:
  • amFunnelChart:
  • amRadarChart:
  • amSerialChart:
  • amPieChart:
  • amGanttChart:
  • amXYChart:

Details

amAngularGaugeChart is a shortcut for instantiating AmChart of type gauge

amFunnelChart is a shortcut for instantiating AmChart of type funnel

amRadarChart is a shortcut for instantiating AmChart of type radar

amSerialChart is a shortcut constructor for instantiating AmChart of type serial

amPieChart is a shortcut constructor for instantiating AmChart of type pie

amGanttChart is a constructor for instantiating AmChart of type gantt

amXYChart is a shortcut constructor for instantiating AmChart of type xy

Method 'addAxe' is deprecated, use 'addAxis'.

Method setGraph is only valid for Gantt Charts.

'addSubData' allows to add subdata for a chart with drilldown. In this case, categoryIDs indicates corresponding indice(s) of the dataProvider where to add the data.

For method addValueAxes: valueAxis is optional.

Method setValueAxis is only valid for Gantt charts.

Examples

Run this code
new("AmChart", valueField = "value")
amChart(type = "pie")
amAngularGaugeChart()
amFunnelChart(marginLeft = 15)
amRadarChart()
amSerialChart(creditsPostion = "top-right")
amPieChart()
amGanttChart(segmentsField = "segments")
amXYChart()
allLabels <- list(label(text = "balloonText"), label(text = "column"))
print(setAllLabels(.Object = amSerialChart(), allLabels = allLabels))
# equivalent to:
print(amSerialChart(allLabels = allLabels))
# ---
print(addLabel(.Object = amSerialChart(), text = "balloonText"))
# equivalent to:
label_obj <- label(text = "balloonText")
print(addLabel(.Object = amSerialChart(), label = label_obj))
## Not run: 
# # Error use cases:
#  addLabel(.Object = amChart())
#  addLabel(.Object = amChart(), label = "another class")
# ## End(Not run)
# ---
arrows_ls <- list(gaugeArrow(value = 130), gaugeArrow(value = 150) )
print(setArrows(.Object = amAngularGaugeChart(), arrows = arrows_ls))
# equivalent to:
print(amAngularGaugeChart(arrows = arrows_ls))
# ---
print(addArrow(.Object = amAngularGaugeChart(), value = 10))
# equivalent to:
gaugeArrow_obj <- gaugeArrow(value = 10)
print(addArrow(.Object = amAngularGaugeChart(), arrow = gaugeArrow_obj))
## Not run: 
# # Error use cases:
# addArrow(.Object = amAngularGaugeChart())
# addArrow(.Object = amAngularGaugeChart(), arrow = "error")
# ## End(Not run)
# ---
axes_ls <- list(gaugeAxis(value = 130), gaugeAxis(value = 150))
setAxes(.Object = amAngularGaugeChart(), axes = axes_ls)
# equivalent to:
amChart(axes = axes_ls)
# ---
addAxis(.Object = amAngularGaugeChart(), startValue = 0, endValue = 100, valueInterval = 10)

# equivalent to:

gaugeAxis_obj <- gaugeAxis(startValue = 0, enValue = 100, valueInterval = 10)
addAxis(.Object = amAngularGaugeChart(), axe = gaugeAxis_obj)

## Not run: 
# # Error use cases:
# addAxis(.Object = amAngularGaugeChart())
# addAxis(.Object = amAngularGaugeChart(), axis = "error")
# ## End(Not run)

# ---
setBalloon(.Object = amSerialChart(), adjustBorderColor = TRUE, fillColor = "#FFFFFF",
           color = "#000000", cornerRadius = 5)
# equivalent to:
amBalloon_obj <- amBalloon(adjustBorderColor = TRUE, fillColor = "#FFFFFF",
                           color = "#000000", cornerRadius = 5)
print(setBalloon(.Object = amSerialChart(), amBalloon = amBalloon_obj))
## Not run: 
# # Error use cases:
# setBalloon(.Object = amSerialChart())
# setBalloon(.Object = amSerialChart(), amBalloon = "error")
# ## End(Not run)
# ---
print(setCategoryAxis(.Object = amSerialChart(), gridPosition = "start"))
# equivalent to:
categoryAxis_obj <- categoryAxis(gridPosition = "start")
print(setCategoryAxis(.Object = amSerialChart(), categoryAxis = categoryAxis_obj))
## Not run: 
# # The argument categoryAxis must be an object of class CategoryAxis
# setCategoryAxis(.Object = amSerialChart(), categoryAxis = "error")
# ## End(Not run)
# ---
print(setCategoryField(.Object = amSerialChart(), categoryField = "country"))
# with default value, nor argument needed
print(setChartCursor(.Object = amSerialChart()))
# other example
print(setChartCursor(.Object = amSerialChart(), oneBallOnly = TRUE))
# equivalent to
chartCursor_obj <- chartCursor(oneBallOnly = TRUE)
print(setChartCursor(.Object = amSerialChart(), chartCursor = chartCursor_obj))
## Not run: 
# Error use case:
# setChartCursor(.Object = amSerialChart(), chartCursor = "error")
# ## End(Not run)
# ---
# Add the default scrollbar
print(setChartScrollbar(.Object = amSerialChart()))
# equivalent to:
chartScrollbar_obj <- chartScrollbar(updateOnReleaseOnly = FALSE)
print(setChartScrollbar(.Object = amSerialChart(), chartScrollbar = chartScrollbar_obj))
## Not run: 
# setChartScrollbar(.Object = amSerialChart(), chartScrollbar = list(updateOnReleaseOnly = FALSE))
# ## End(Not run)
# ---
print(setCreditsPosition(.Object = amPieChart(), creditsPosition = "top-right"))
## Not run: 
# Error use case:
# setCreditsPosition(.Object = amPieChart(), creditsPosition = "top-center")
# ## End(Not run)
# ---
print(setDataLoader(.Object = amSerialChart(), url = "data.json", format = "json"))
# ---
dataProvider_obj <- data.frame(key = c("FR", "US", "GER", "ENG", "IT" ),
                               value = round(runif(5, max = 100)))
print(setDataProvider(.Object = amPieChart(), dataProvider = dataProvider_obj))
# ---
print(setExport(.Object = amSerialChart()))
# ---
graphs_ls <- list(amGraph(balloonText = "balloonText"), amGraph(type = "column"))
print(setGraphs(.Object = amChart(), graphs = graphs_ls))
## Not run: 
# graphs_ls <- list(list(balloonText = "balloonText"), list(type = "column"))
# setGraphs(.Object = amChart(), graphs = graphs_ls)
# ## End(Not run)
# ---
print(addGraph(.Object = amSerialChart(), balloonText = "balloonText", "type" = "column"))
# equivalent to
amGraph_obj <- amGraph(balloonText = "balloonText", "type" = "column")
print(addGraph(.Object = amSerialChart(), amGraph = amGraph_obj))
# ---
print(setGraph(.Object = amGanttChart(), id = "amGraph-1"))
# equivalent to
amGraph_obj <- amGraph(id = "amGraph-1")
print(setGraph(.Object = amGanttChart(), amGraph = amGraph_obj))
# ---
guides_ls <- list(guide(fillAlpha = .1), guide(fillAlpha = .5))
print(setGuides(.Object = amSerialChart(), guides = guides_ls))
# or...
amSerialChart(guides = guides_ls)
# ---
print(addGuide(.Object = amSerialChart(), fillAlpha = .1, value = 0, toVAlue = 10))
# equivalent to
guide_obj <- guide(fillAlpha = .1, value = 0, toValue = 10, valueAxis = "1")
print(addGuide(.Object = amSerialChart(), guide = guide_obj))
# ---
print(setLegend(.Object = amChart(), amLegend = amLegend(useGraphSettings = TRUE)))
# equivalent to:
print(setLegend(.Object = amChart(), useGraphSettings = TRUE))
# ---
print(setResponsive(.Object = amSerialChart(), enabled = FALSE))
# ---
pipeR::pipeline(
  amGanttChart(segmentsField = "segments"),
  setDataProvider(data.frame(category = c( "John", "Julia"))),
  addSegment(1, data.frame(start = 7, duration = 2:3, task = c("Task #1", "Task #2"))),
  addSegment(2, data.frame(start = 10, duration = 2:3, task = c("Task #1", "Task #2")))
)
# ---
ls <- list(data.frame(start = 7, duration = 2:3, task = c("Task #1", "Task #2")),
           data.frame(start = 10, duration = 2:3, task = c("Task #1", "Task #2")))
pipeR::pipeline(
  amGanttChart(segmentsField = "segments"),
  setDataProvider(data.frame(category = c( "John", "Julia"))),
  addSegment(1:2,  ls)
)
# ---
amChart_obj <- amChart(dataProvider = data.frame(a = 1:5, b = 6:10))
print(addSubData(.Object = amChart_obj, categoryIDs = 3, data = data.frame(a = 1:10, b = 11:20)))
# ---
print(setSubChartProperties(.Object = amSerialChart(), type = "serial"))
# ---
titles_ls <- list(title(text = "balloonText"), title(text = "column"))
print(setTitles(.Object = amXYChart(), titles = titles_ls))
# or...
print(amChart(titles = titles_ls))
# ---
print(addTitle(.Object = amPieChart(), text = "balloonText", size = 15))
# equivalent to
title_obj <- title(text = "balloonText", size = 15)
print(addTitle(.Object = amPieChart(), title = title_obj))
# ---
trendLines <- list(trendLine(initialValue = 1, finalValue = 5),
                   trendLine(initialValue = 7, finalValue = 19))
print(setTrendLines(.Object = amChart(), trendLines = trendLines))
# or...
print(amChart(trendLines = trendLines)) # Equivalent
addTrendLine(.Object = amSerialChart(), initialValue = 1, initialXValue = 1,
             finalValue = 11, finalXValue = 12)
# equivalent to:
trendLine_obj <- trendLine(initialValue = 1, initialXValue = 1, finalValue = 11, finalXValue = 12)
addTrendLine(.Object = amSerialChart(), trendLine = trendLine_obj)
setType(.Object = amChart(), type = "pie")
# equivalent to:
amPieChart()
valueAxes <- list(valueAxis(axisTitleOffset = 12, tickLength = 10),
                  valueAxis(axisTitleOffset = 10, tickLength = 10))
setValueAxes(.Object = amSerialChart(), valueAxes = valueAxes)
# or...
amSerialChart(valueAxes = valueAxes)
# ---
addValueAxes(.Object = amSerialChart(), axisTitleOffset = 12, tickLength = 10)
addValueAxis(.Object = amSerialChart(), axisTitleOffset = 12, tickLength = 10)
# equivalent to:
valueAxis_obj <- valueAxis(axisTitleOffset = 12, tickLength = 10)
addValueAxes(.Object = amSerialChart(), valueAxis = valueAxis_obj)
# ---
print(setValueAxis(.Object = amGanttChart()))
print(setValueAxis(.Object = amGanttChart(), type = "date"))

Run the code above in your browser using DataLab