AmPieChart的属性、方法和事件官方手册

AmPieChart是amcharts图表控件中的饼图对象。

Properties 属性
PropertyTypeDefaultDescription
addClassNamesBooleanfalseSpecifies, if class names should be added to chart elements.
adjustPrecisionBooleanfalseSometimes, because of a rounding, percent of a sum of all slices is not equal to 100%. If you set this to true, when this case happens, number of decimals will be increased so that sum would become 100%.
allLabelsArray[Label][]Array of Labels. Example of label object, with all possible properties:
{"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"}
alphaNumber1Opacity of all slices.
alphaFieldString Name of the field in chart's dataProvider which holds slice's alpha.
angleNumber0Pie lean angle (for 3D effect). Valid range is 0 - 90.
autoResizeBooleantrueSet this to false if you don't want chart to resize itself whenever its parent container size changes.
backgroundAlphaNumber0Opacity of background. Set it to >0 value if you want backgroundColor to work. However we recommend changing div's background-color style for changing background color.
backgroundColorColor#FFFFFFBackground color. You should set backgroundAlpha to >0 value in order background to be visible. We recommend setting background color directly on a chart's DIV instead of using this property.
balloonAmBalloonAmBalloonThe chart creates AmBalloon class itself. If you want to customize balloon, get balloon instance using this property, and then change balloon's properties.
balloonTextString[[title]]: [[percents]]% ([[value]])\n[[description]]Balloon text. The following tags can be used: [[value]], [[title]], [[percents]], [[description]] or any other field name from your data provider. HTML tags can also be used.
baseColorColor Color of the first slice. All the other will be colored with darker or brighter colors.
borderAlphaNumber0Opacity of chart's border. Value range is 0 - 1.
borderColorColor#000000Color of chart's border. You should set borderAlpha >0 in order border to be visible. We recommend setting border color directly on a chart's DIV instead of using this property.
chartDataArray[Object] Read-only. Array of Slice objects.
classNamePrefixStringamchartsThis prefix is added to all class names which are added to all visual elements of a chart in case addClassNames is set to true.
colorColor#000000Text color.
colorFieldString Name of the field in chart's dataProvider which holds slice's color.
colorsArray[Color]["#FF0F00", "#FF6600", "#FF9E01", "#FCD202", "#F8FF01", "#B0DE09", "#04D215", "#0D8ECF", "#0D52D1", "#2A0CD0", "#8A0CCF", "#CD0D74", "#754DEB", "#DDDDDD", "#999999", "#333333", "#000000", "#57032A", "#CA9726", "#990000", "#4B0C25"]Specifies the colors of the slices, if the slice color is not set. If there are more slices than colors in this array, the chart picks random color.
creditsPositionStringtop-leftNon-commercial version only. Specifies position of link to amCharts site. Allowed values are: top-left, top-right, bottom-left and bottom-right.
dataProviderArray[Object] Array of data objects, for example: [{country:"US", value:524},{country:"UK", value:624},{country:"Lithuania", value:824}]. You can have any number of fields and use any field names. In case of AmMap, data provider should be MapData object.

The data set data.

Important: if you are using date/time-based category axis, the data points needs to come pre-ordered in ascending order. Data with incorrect order might result in visual and functional glitches on the chart.
decimalSeparatorString.Decimal separator.
defsObject Using this property you can add any additional information to SVG, like SVG filters or clip paths. The structure of this object should be identical to XML structure of a object you are adding, only in JSON format.
depth3DNumber0Depth of the pie (for 3D effect).
descriptionFieldString Name of the field in chart's dataProvider which holds a string with description.
exportObject Export config. Specifies how export to image/data export/print/annotate menu will look and behave. You can find a lot of examples in amcharts/plugins/export folder. More details can be found here.
fontFamilyStringVerdanaFont family.
fontSizeNumber11Font size.
gradientRatioArray[Number][]Example: [0,10]. Will make slices to be filled with color gradients.
groupedAlphaNumber1Opacity of the group slice. Value range is 0 - 1.
groupedColorColor Color of the group slice. The default value is not set - this means the next available color from "colors" array will be used.
groupedDescriptionString Description of the group slice.
groupedPulledBooleanfalseIf this is set to true, the group slice will be pulled out when the chart loads.
groupedTitleStringOtherTitle of the group slice.
groupPercentNumber0If there is more than one slice whose percentage of the pie is less than this number, those slices will be grouped together into one slice. This is the "other" slice. It will always be the last slice in a pie.
handDrawnBooleanfalseIf you set this to true, the lines of the chart will be distorted and will produce hand-drawn effect. Try to adjust chart.handDrawScatter and chart.handDrawThickness properties for a more scattered result.
handDrawScatterNumber2Defines by how many pixels hand-drawn line (when handDrawn is set to true) will fluctuate.
handDrawThicknessNumber1Defines by how many pixels line thickness will fluctuate (when handDrawn is set to true).
hideBalloonTimeNumber150Time, in milliseconds after which balloon is hidden if the user rolls-out of the object. Might be useful for AmMap to avoid balloon flickering while moving mouse over the areas. Note, this is not duration of fade-out. Duration of fade-out is set in AmBalloon class.
hideLabelsPercentNumber0Slices with percent less then hideLabelsPercent won't display labels This is useful to avoid cluttering up the chart, if you have a lot of small slices. 0 means all labels will be shown.
hoverAlphaNumber1Opacity of a hovered slice. Value range is 0 - 1.
innerRadiusNumber/String0Inner radius of the pie, in pixels or percents.
labelFunction  You can use it to format data labels in any way you want. Chart will call this method and will pass Slice object and formatted text as attributes. This function should return string which will be displayed as label.
labelRadiusNumber20The distance between the label and the slice, in pixels. You can use negative values to put the label on the slice.
labelRadiusFieldString Name of the field in dataProvider which specifies the length of a tick. Note, the chart will not try to arrange labels automatically if this property is set.
labelsEnabledBooleantrueSpecifies whether data labels are visible.
labelTextString[[title]]: [[percents]]%Label text. The following tags can be used: [[value]], [[title]], [[percents]], [[description]] or any other field name from your data provider.
labelTickAlphaNumber0.2Label tick opacity. Value range is 0 - 1.
labelTickColorColor#000000Label tick color.
languageString Allows changing language easily. Note, you should include language js file from amcharts/lang or ammap/lang folder and then use variable name used in this file, like chart.language = "de"; Note, for maps this works differently - you use language only for country names, as there are no other strings in the maps application.
legendAmLegend Legend of a chart.
legendDivString Read-only. Reference to the div of the legend.
marginBottomNumber10Bottom margin of the chart.
marginLeftNumber0Left margin of the chart.
marginRightNumber0Right margin of the chart.
marginTopNumber10Top margin of the chart.
maxLabelWidthNumber200If width of the label is bigger than maxLabelWidth, it will be wrapped.
minRadiusNumber10Minimum radius of the pie, in pixels.
outlineAlphaNumber0Outline opacity. Value range is 0 - 1.
outlineColorColor#FFFFFFOutline color.
outlineThicknessNumber1Pie outline thickness.
panEventsEnabledBooleantrueThis setting affects touch-screen devices only. If a chart is on a page, and panEventsEnabled are set to true, the page won't move if the user touches the chart first. If a chart is big enough and occupies all the screen of your touch device, the user won’t be able to move the page at all. If you think that selecting/panning the chart or moving/pinching the map is a primary purpose of your users, you should set panEventsEnabled to true, otherwise - false.
pathStringamcharts/Specifies absolute or relative path to amCharts files, i.e. "amcharts/". (where all .js files are located)

If relative URLs are used, they will be relative to the current web page, displaying the chart.

You can also set path globally, using global JavaScript variable AmCharts_path. If this variable is set, and "path" is not set in chart config, the chart will assume the path from the global variable. This allows setting amCharts path globally. I.e.:

var AmCharts_path = "/libs/amcharts/";


"path" parameter will be used by the charts to locate it's files, like images, plugins or patterns.
pathToImagesString Specifies path to the folder where images like resize grips, lens and similar are.

IMPORTANT: Since V3.14.12, you should use "path" to point to amCharts directory instead. The "pathToImages" will be automatically set and does not need to be in the chart config, unless you keep your images separately from other amCharts files.
patternFieldString Field name in your data provider which holds pattern information. Value of pattern should be object with url, width, height of an image, optionally it might have x, y, randomX and randomY values. For example: {"url":"../amcharts/patterns/black/pattern1.png", "width":4, "height":4}. Check amcharts/patterns folder for some patterns. You can create your own patterns and use them. Note, x, y, randomX and randomY properties won't work with IE8 and older. 3D bar/Pie charts won't work properly with patterns.
percentPrecisionNumber2Precision of percent values. -1 means percent values won't be rounded at all and show as they are.
pieAlphaNumber1Opacity of the slices. You can set the opacity of individual slice too.
pieXNumber/String You can set fixed position of a pie center, in pixels or in percents.
pieYNumber/String You can set fixed position of a pie center, in pixels or in percents.
precisionNumber-1Precision of values. -1 means values won't be rounded at all and show as they are.
prefixesOfBigNumbersArray[Object][{number:1e+3,prefix:"k"},{number:1e+6,prefix:"M"},{number:1e+9,prefix:"G"},{number:1e+12,prefix:"T"},{number:1e+15,prefix:"P"},{number:1e+18,prefix:"E"},{number:1e+21,prefix:"Z"},{number:1e+24,prefix:"Y"}]Prefixes which are used to make big numbers shorter: 2M instead of 2000000, etc. Prefixes are used on value axes and in the legend. To enable prefixes, set usePrefixes property to true.
prefixesOfSmallNumbersArray[Object][{number:1e-24, prefix:"y"},{number:1e-21, prefix:"z"},{number:1e-18, prefix:"a"},{number:1e-15, prefix:"f"},{number:1e-12, prefix:"p"},{number:1e-9, prefix:"n"},{number:1e-6, prefix:"μ"},{number:1e-3, prefix:"m"}]Prefixes which are used to make small numbers shorter: 2μ instead of 0.000002, etc. Prefixes are used on value axes and in the legend. To enable prefixes, set usePrefixes property to true.
pulledFieldString Name of the field in chart's dataProvider which holds a boolean value telling the chart whether this slice must be pulled or not.
pullOutDurationNumber1Pull out duration, in seconds.
pullOutEffectStringbouncePull out effect. Possible values are: easeOutSine, easeInSine, elastic, bounce
pullOutOnlyOneBooleanfalseIf this is set to true, only one slice can be pulled out at a time. If the viewer clicks on a slice, any other pulled-out slice will be pulled in.
pullOutRadiusNumber/String20%Pull out radius, in pixels or percents
pullOutRadiusNumber/String20%Pull out radius, in pixels or percents
radiusNumber/String Radius of a pie, in pixels or percents. By default, radius is calculated automatically.
sequencedAnimationBooleantrueSpecifies whether the animation should be sequenced or all slices should appear at once.
startAlphaNumber0Initial opacity of all slices. Slices will fade in from startAlpha.
startAngleNumber90Angle of the first slice, in degrees. This will work properly only if "depth3D" is set to 0. If "depth3D" is greater than 0, then there can be two angles only: 90 and 270. Value range is 0-360.
startDurationNumber1Duration of the animation, in seconds.
startEffectStringbounceAnimation effect. Possible values are: easeOutSine, easeInSine, elastic, bounce
startRadiusNumber/String500%Radius of the positions from which the slices will fly in.
themeStringnoneTheme of a chart. Config files of themes can be found in amcharts/themes/ folder. More info about using themes.
thousandsSeparatorString,Thousands separator.
titleFieldString Name of the field in chart's dataProvider which holds slice's title.
titlesArray[Title][]Array of Title objects.
typeString Type of a chart. Required when creating chart using JSON. Possible types are: serial, pie, xy, radar, funnel, gauge, map, stock.
urlFieldString Name of the field in chart's dataProvider which holds url which would be accessed if the user clicks on a slice.
urlTargetString_selfIf url is specified for a slice, it will be opened when user clicks on it. urlTarget specifies target of this url. Use _blank if you want url to be opened in a new window.
usePrefixesBooleanfalseIf true, prefixes will be used for big and small numbers. You can set arrays of prefixes via prefixesOfSmallNumbers and prefixesOfBigNumbers properties.
valueFieldString Name of the field in chart's dataProvider which holds slice's value.
versionString Read-only. Indicates current version of a script.
visibleInLegendFieldString Name of the field in chart's dataProvider which holds boolean variable defining whether this data item should have an entry in the legend.
visibleInLegendFieldString Name of the field in chart's dataProvider which holds boolean variable defining whether this data item should have an entry in the legend.

Methods 方法

NameParametersReturnsDescription
addLabel(x, y, text, align, size, color, rotation, alpha, bold, url)x - horizontal coordinate y - vertical coordinate text - label's text align - alignment (left/right/center) size - text size color - text color rotation - angle of rotation alpha - label alpha bold - specifies if text is bold (true/false), url - url of a Adds a label on a chart. You can use it for labeling axes, adding chart title, etc. x and y coordinates can be set in number, percent, or a number with ! in front of it - coordinate will be calculated from right or bottom instead of left or top.
addLegend(legend, legendDivID)legend - AmLegend, legendDivID - id or reference to legend div (optional) Adds a legend to the chart. By default, you don't need to create div for your legend, however if you want it to be positioned in some different way, you can create div anywhere you want and pass id or reference to your div as a second parameter. (NOTE: This method will not work on StockPanel.)
addListener(type, handler)type - string like 'dataUpdated' (should be listed in 'events' section of this class or classes which extend this class). handler - function which is called when event happens Adds event listener to the object.
addTitle(text, size, color, alpha, bold)text - text of a title size - font size color - title color alpha - title opacity bold - boolean value indicating if title should be bold. Adds title to the top of the chart. Pie, Radar positions are updated so that they won't overlap. Plot area of Serial/XY chart is also updated unless autoMargins property is set to false. You can add any number of titles - each of them will be placed in a new line. To remove titles, simply clear titles array: chart.titles = []; and call chart.validateNow() method.
animateAgain()  You can trigger the animation of the pie chart.
clear()  Clears the chart area, intervals, etc.
clearLabels()  Removes all labels added to the chart.
clickSlice(index)index - the number of a slice or Slice object. You can trigger the click on a slice from outside.
hideSlice(index)index - the number of a slice or Slice object. Hides slice.
invalidateSize()  Use this method to force the chart to resize to it's current container size.
makeChart(container, config, delay)container - id of a DIV or DIV object which holds the chart - config contains the whole setup for the chart - delay in milliseconds to delay the initiation of the chartchart instanceThis method allows to create charts with a single config.
removeLegend()  Removes chart's legend.
removeListener(chart, type, handler)chart - chart object, type - event name, handler - method Removes event listener from chart object.
rollOutSlice(index)index - the number of a slice or Slice object. You can simulate roll-out of a slice from outside.
rollOverSlice(index)index - the number of a slice or Slice object. You can simulate roll-over a slice from outside.
showSlice(index)index - the number of a slice or Slice object. Shows slice.
validateData()  This method should be called after data in your data provider changed or a new array was set to dataProvider. After calling this method the chart will parse data and redraw.
validateNow(validateData, skipEvents)  This method should be called after you changed one or more properties of any class. The chart will redraw after this method is called.Both attributes, validateData and skipEvents are optional (false by default).
write(container)container - id of a DIV or DIV object which will hold the chart Adds chart to the specified DIV.

Events 事件

NameEvent objectDescription
clickSlice{type:"clickSlice", dataItem:Slice, event:MouseEvent}Dispatched when user clicks on a slice. Event is an instance of original mouse event.
dataUpdated{type:"dataUpdated", chart:AmChart}Dispatched when chart is build for the first time or after validateData() method was called.
drawn{type:"drawn", chart:AmChart}Fired every time chart is drawn - on zoom, hide graph, etc.
init{type:"init", chart:AmChart}Dispatched when chart is build for the first time.
pullInSlice{type:"pullInSlice", dataItem:Slice, event:MouseEvent}Dispatched when user clicks on a slice and the slice is pulled-in. Event is an instance of original mouse event.
pullOutSlice{type:"pullOutSlice", dataItem:Slice, event:MouseEvent}Dispatched when user clicks on a slice and the slice is pulled-out. Event is an instance of original mouse event.
rendered{type:"rendered", chart:AmChart}Dispatched when the chart is build for the first time and each time after chart.validateNow() method is called and the chart is build.
rightClickSlice{type:"rightClickSlice", dataItem:Slice, event:MouseEvent}Dispatched when user right-clicks the slice. Event is an instance of original mouse event.
rollOutSlice{type:"rollOutSlice", dataItem:Slice, event:MouseEvent}Dispatched when user rolls-out of the slice. Event is an instance of original mouse event.
rollOverSlice{type:"rollOverSlice", dataItem:Slice, event:MouseEvent}Dispatched when user rolls-over the slice. Event is an instance of original mouse event.

有话要说