Learn R Programming

rAmCharts (version 2.0.2)

initialize,AmChart-method: Creates an AmChart

Description

Method to initialize any S4 class provided by the package.

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)
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, ...)
addSegment(.Object, categoryIDs, sgts)
"addSegment"(.Object, categoryIDs, sgts)
addSubData(.Object, categoryIDs, data)
"addSubData"(.Object, categoryIDs, data)
setSubChartProperties(.Object, .subObject = NULL, ...)
"setSubChartProperties"(.Object, .subObject = NULL, ...)
setTheme(.Object, theme)
"setTheme"(.Object, theme)
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 a label object, with all possible properties: label(x = 20, y = 20, text = "this is a label", align = "left", size = 12, color = "#CC0000", alpha = 1, rotation = 0, bold = TRUE, url = "http=//www.amcharts.com"). Run api("Label") for more informations.
arrows
list of GaugeArrow. Only valid for gauge charts. Run api("GaugeArrow") for more informations.
axes
list of GaugeAxis properties. Only valid for gauge charts. Run api("GaugeAxis") for more informations.
balloon
AmBalloon. Creates the balloons (tooltips) of the chart. It follows the mouse cursor when you roll-over the data items. The framework automatically generates the instances you just have to adjust the appearance to your needs. Run api("AmBalloon") for more informations.
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. Run api("CategoryAxis") for more informations.
categoryField
character, category field name indicates the name of the field in your dataProvider object which will be used for category axis values.
chartCursor
ChartCursor. Chart's cursor. Run api("ChartCursor") for more informations.
chartScrollbar
ChartScrollbar. Chart's scrollbar. Run api("ChartScrollbar") for more informations.
creditsPosition
character, specifies position of the amCharts' website link. 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. Run api("AmGraph") for more informations.
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 informations.
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 be assigned to the category axis, otherwise to the first value axis, unless you specify a different valueAxes for the guide. Run api("Guide") for more informations.
legend
AmLegend. Legend of a chart. Run api("AmLegend") for more informations.
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 informations.
trendLines
list of TrendLine objects added to the chart. You can add trend lines to a chart using this list or access already existing trend lines. Run api("TrendLine") for more informations.
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 informations.
valueAxis
ValueAxis. Only valid for Gantt Charts. Set it's type to "date" if your data is date or time based. Run api("ValueAxis") for more informations.
...
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.
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.

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 addValueAxis: valueAxis is optional. Method addValueAxes is deprecated.

Method setValueAxis is only valid for Gantt charts.

See Also

Refer to http://docs.amcharts.com/3/javascriptcharts/.

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"))
amSerialChart(allLabels = allLabels)

# ---

addLabel(.Object = amSerialChart(), text = "balloonText")
# equivalent to:
label_obj <- label(text = "balloonText")
addLabel(.Object = amSerialChart(), label = label_obj)

# ---

arrows_ls <- list(gaugeArrow(value = 130), gaugeArrow(value = 150))
amAngularGaugeChart(arrows = arrows_ls)

# ---

addArrow(.Object = amAngularGaugeChart(), value = 10)
# equivalent to:
gaugeArrow_obj <- gaugeArrow(value = 10)
addArrow(.Object = amAngularGaugeChart(), arrow = gaugeArrow_obj)

# ---

axes_ls <- list(gaugeAxis(value = 130), gaugeAxis(value = 150))
setAxes(.Object = amAngularGaugeChart(), axes = axes_ls)
# If possible, simplify your code by using the constructor:
amAngularGaugeChart(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(), axis = gaugeAxis_obj)

# ---

setBalloon(.Object = amSerialChart(), adjustBorderColor = TRUE, fillColor = "#FFFFFF",
           color = "#000000", cornerRadius = 5)
# equivalent to:
amBalloon_obj <- amBalloon(adjustBorderColor = TRUE, fillColor = "#FFFFFF",
                           color = "#000000", cornerRadius = 5)
setBalloon(.Object = amSerialChart(), amBalloon = amBalloon_obj)

# ---

setCategoryAxis(.Object = amSerialChart(), gridPosition = "start")
# equivalent to:
categoryAxis_obj <- categoryAxis(gridPosition = "start")
setCategoryAxis(.Object = amSerialChart(), categoryAxis = categoryAxis_obj)

# ---
setCategoryField(.Object = amSerialChart(), categoryField = "country")
# ---

# with default value, no argument needed
setChartCursor(.Object = amSerialChart())
# other example
setChartCursor(.Object = amSerialChart(), oneBallOnly = TRUE)
# equivalent to
chartCursor_obj <- chartCursor(oneBallOnly = TRUE)
setChartCursor(.Object = amSerialChart(), chartCursor = chartCursor_obj)

# ---

# Add the default scrollbar
setChartScrollbar(.Object = amSerialChart())
# equivalent to:
chartScrollbar_obj <- chartScrollbar(updateOnReleaseOnly = FALSE)
setChartScrollbar(.Object = amSerialChart(), chartScrollbar = chartScrollbar_obj)

# ---

setCreditsPosition(.Object = amPieChart(), creditsPosition = "top-right")

# ---

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)))
setDataProvider(.Object = amPieChart(), dataProvider = dataProvider_obj)

# ---

graphs_ls <- list(graph(balloonText = "balloonText"), graph(type = "column"))
setGraphs(.Object = amSerialChart(), graphs = graphs_ls)

# ---

addGraph(.Object = amSerialChart(), balloonText = "balloonText", "type" = "column")
# equivalent to
amGraph_obj <- amGraph(balloonText = "balloonText", "type" = "column")
addGraph(.Object = amSerialChart(), amGraph = amGraph_obj)

# ---

print(setGraph(.Object = amGanttChart(), id = "amGraph-1"))
# equivalent to:
amGraph_obj <- amGraph(id = "amGraph-1")
setGraph(.Object = amGanttChart(), amGraph = amGraph_obj)

# ---

guides_ls <- list(guide(fillAlpha = .1), guide(fillAlpha = .5))
amSerialChart(guides = guides_ls)

# ---
addGuide(.Object = amSerialChart(), fillAlpha = .1, value = 0, toVAlue = 10)
# equivalent to
guide_obj <- guide(fillAlpha = .1, value = 0, toValue = 10, valueAxis = "1")
addGuide(.Object = amSerialChart(), guide = guide_obj)
# ---

setLegend(.Object = amChart(), amLegend = amLegend(useGraphSettings = TRUE))
# equivalent to:
setLegend(.Object = amChart(), useGraphSettings = TRUE)

# ---

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))
addSubData(.Object = amChart_obj, categoryIDs = 3, data = data.frame(a = 1:10, b = 11:20))

# ---

setSubChartProperties(.Object = amSerialChart(), type = "serial")

# ---

setTheme(.Object = amPieChart(), theme = "dark")

# ---

titles_ls <- list(title(text = "balloonText"), title(text = "column"))
setTitles(.Object = amXYChart(), titles = titles_ls)
# or...
amXYChart(titles = titles_ls)

# ---

addTitle(.Object = amPieChart(), text = "balloonText", size = 15)
# equivalent to
title_obj <- title(text = "balloonText", size = 15)
addTitle(.Object = amPieChart(), title = title_obj)

# ---

trendLines <- list(trendLine(initialValue = 1, finalValue = 5),
                   trendLine(initialValue = 7, finalValue = 19))
setTrendLines(.Object = amSerialChart(), trendLines = trendLines)
# or... 
amSerialChart(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)

# ---

addValueAxis(.Object = amSerialChart(), axisTitleOffset = 12, tickLength = 10)
# equivalent to:
valueAxis_obj <- valueAxis(axisTitleOffset = 12, tickLength = 10)
addValueAxis(.Object = amSerialChart(), valueAxis = valueAxis_obj)

# ---

setValueAxis(.Object = amGanttChart())
setValueAxis(.Object = amGanttChart(), type = "date")

Run the code above in your browser using DataLab