1. Chart properties
1. Refresh
invalidate(): Calling in the chart will cause it to refresh and redraw
notifyDataChanged(): Let the chart know that the underlying data it depends on has changed, and perform all necessary recalculations (such as offsets, lenged ,maximum value minimum value...). It is needed when adding data dynamically.
2. Print log
setLogEnable(boolean enabled): Set to true to activate the logcat output of the chart. But this is bad for performance and should be kept disabled if not necessary.
3. Chart property
setBackgroundColor(int color): Set the background color, which will cover the entire chart view. Also, the background color can be set in the layout file .xml.
setDescription(Description desc): Set the description text of the chart, which will be displayed in the lower right corner of the chart.
setDescriptionColor(int color): Set the color of the description text.
setDescriptionPosition(float x, floaty): Customize the position of the description text on the screen (unit is pixel).
setDescriptionTypeface(Typeface t): Set the font of the description text.
setDescriptionTextSize(float size): Set the description text in pixels, the minimum is 6f, and the maximum is 16f.
setNoDataTextDescription(String desc): Set the description text displayed when the chart is empty.
setDrawGridBackground(boolean enabled): If enabled, the background rectangle behind the chart drawing area will be drawn.
setGridBackgroundColor(int color): Sets the color the grid background should be drawn with.
setDrawBorder(boolean enabled): Enable/disable drawing the chart border (line around the chart).
setBorderColor(int color): Set the color of the border line of the chart.
setBorderWidth(float width): Set the width of the chart border line, in dp.
setMaxVisibleValueCount(int count): Sets the maximum number of chartcounts that are visible to draw. Only valid when setDrawValues() is set to true.
4. Enable/disable gesture interaction
setTouchEnabled(boolean enabled): Enable/disable all possible touch interactions with the chart.
setDragEnabled(boolean enabled): Enable/disable dragging (panning) the chart.
setScaleEnabled(boolean enabled): Enable/disable scaling both axes on the chart.
setScaleXEnabled(boolean enabled): Enable/disable scaling on the X axis.
setScaleYEnabled(boolean enabled): Enable/disable scaling on the Y axis.
setPinchZoom (boolena enabled): If set to true, no zoom function. If false, the x-axis and y-axis can be scaled separately.
setDoubleTapToZoomEnabled(booleanenabled): Set to false to disable zooming of the chart by double clicking on it.
setHighlightPerDragEnabled(booleanenabled): Set to true to allow each chart surface to be dragged over and highlighted when it is fully zoomed out. Default: true
setHighlightPerTapEnabled(boolean enabled): Set to false to prevent values from being highlighted by tap gestures. Values can still be highlighted by dragging or programmatically. Default: true.
5. Chart throwing/deceleration
setDragDecelerationEnabled(boolean enabled): If set to true, the finger slides and throws the chart and continues to decelerate and scroll. Default: true.
setDragDecelerationFrictionCoef (floatcoef): The friction coefficient of deceleration is in the range [0; 1]. The higher the value, the slower the speed. For example, if it is set to 0, it will stop immediately. 1 is an invalid value and is automatically converted to 0.9999.
6. Highlight
highlightValues (Highlight[] highs): Highlight the value, the value of the highlighted click position in the data set. Setting a null or empty array undoes all highlighting.
highlightValue(int xIndex, intdataSetIndex): Highlight the value of the given xIndex in the dataset. Set xIndex or dataSetIndex to -1 to undo all highlighting.
getHighlightd(): Returns a highlight[] which contains the information of all highlighted objects, xIndex and dataSetIndex. Making value highlighting programmatically in Java does not call back onChartValueSelectedListener.
7. Selection callback
MPAndroidChart provides many methods for interactive callbacks, among which OnChartValueSelectedListener is called back when the highlight is clicked.
publicinterface OnChartValueSelectedListener{
/**
*When the value in the chart is clicked
*
* @param e the selected dataset
* @param dataSetIndex the index of the dataset
* @param h the corresponding highlight object
*/
public voidonValueSelected(Entry e, int dataSetIndex, Highlight h);
/**
* When there is no selection
*/
public voidonNothingSelected();
}
Let your class implement this interface and set up to monitor the chart to receive the callback.
8. The gesture callback
listener OnchartGestureListener enables the chart to interact with gesture operations.
publicinterface OnChartGestureListener{
/**
* Callback when touching the chart (press)
*
* @param me
* @param lastPerformedGesture
*/
voidonChartGestureStart(MotionEvent me, ChartTouchListener.ChartGesturelastPerformedGesture);
/**
* Callback when touching the chart (lift, Cancel)
*
* @param me
* @param lastPerformedGesture
*/
voidonChartGestureEnd(MotionEvent me, ChartTouchListener.ChartGesture lastPerformedGesture);
/**
* Callback when chart is long pressed
*
* @param me
*/
public voidonChartLongPressed(MotionEvent me);
/**
* Callback when the chart is double clicked
*
* @param me
*/
public voidonChartDoubleTapped(MotionEvent me);
/**
*Callback when chart is clicked
*
* @param me
*/
public voidonChartSingleTapped(MotionEvent me);
/**
*Callback according to gesture
*
* @param me1
* @param me2
* @param velocityX
* @param velocityY
*/
public voidonChartFling(MotionEvent me1, MotionEvent me2, float velocityX, floatvelocityY);
/**
*Callback when zooming the chart
*
* @param me
* @param scaleX scalefactor on the x-axis
* @param scaleY scalefactor on the y -axis
*/
public voidonChartScale(MotionEvent me, float scaleX, float scaleY);
/**
* Called when moving or rotating
*
* @param me
* @param dX translationdistance on the x-axis
* @param dY translationdistance on the y-axis
*/
public voidonChartTranslate(MotionEvent me, float dX, float dY);
}
Let your class implement this interface and set Monitor the chart to receive callbacks.
chart.setOnChartGestureListener(this);
After setting the listener, the chart will scale and move according to your setXXXEnable(). There is no need to zoom and move the chart in the interface method. The interface method allows you to implement other corresponding functions. For example, if you want to print and zoom, ScaleX, ScaleY:
@Override
public voidonChartScale(MotionEvent me, float scaleX, float scaleY ) {
Log.i("Scale /Zoom", "ScaleX: " + scaleX + ", ScaleY: " + scaleY);
}
9. The chart's own method
Radar Chart (RadarChart)
setWebLineWidth(float width) Set the outward radial lines width
setWebLineWidthInner(floatwidth) Set the inner loop width
setSkipWebLineCount(intcount) Set the hidden count radial lines
setWebAlpha(int alpha) Set the background transparency
setWebColor(int color) Set the outward radial color
setWebColorInner(int color) Set the inner loop color
setDrawWeb(boolean enabled) Set whether to display the radar chart or
bar chart (BarChart)
setDrawValueAboveBar(boolean enabled) Set the number to be displayed on the upper or lower part of the
bar setDrawBarShadow(boolean enabled) Set whether to display all the bars, and the unfilled part will be grayed
out setHighlightFullBarEnabled(boolean enabled) Whether to highlight
setFitBars(boolean enabled) Set whether to display half of the column bars on both sides of the X-axis range
Pie Chart (PieChart)
setUsePercentValues(booleanenabled) Set the value in the chart to display the original value or percent
setHoleColor(int color) Set the center circle background color
setDrawSlicesUnderHole(boolean enable) Set whether to display slices under the center circle
setDrawHoleEnabled(boolean enabled) Set whether to display the center circle part
setCenterText(CharSequence text) Set the center circle text
setDrawCenterText(boolean enabled) Set whether to display the center circle text
setHoleRadius(final float percent) Set the percentage of the radius of the center circle to the radius of the entire pie chart, the default is 50%
setTransparentCircleColor(int color) Set the color of the transparent circle
setTransparentCircleRadius(final float percent) Set the percentage of the radius of the transparent circle to the radius of the entire pie chart, the default is 55%
setTransparentCircleAlpha( int alpha) Set the transparency of the transparent circle
setMaxAngle(float maxangle) Set the maximum angle of the pie chart, 90<= maxangle<=360
Second, coordinate axis
1, Document
AxisBase is the parent class of XAxis and YAxis AxisBase
The base class of all labels
XAxis X Axis label settings. Just use the setter method to modify it, don't access the public variable directly. (Not all Xlabls are available for RadarChart spider webs.)
YAxis Y axis label settings and its entries. Only use setter methods to modify it, don't access public variables directly. (Not all Ylabls are available for RadarChart spider webs.) Customizations that affect the value range of the axes need to be applied before setting data for the chart.
2. Overview
The method mentioned below can be applied to both axes.
The "axis" class allows a specific Style, consisting of the following components/parts (which can be included):
the label for the axis (y-axis is drawn vertically or the x-axis is oriented horizontally), and the contain axis' description value.
The so-called axis-line is drawn directly next to the label and parallel.
grid-lines are horizontal and originate from each axis label.
LimitLines allow special information to be presented, such as boundaries or limits.
3. Control the drawing of the axis.
setEnable(boolean enabled): Set the axis to enable or disable. If false, no part of this axis will be drawn (no axes/sticky notes etc).
setDrawGridLines(boolean enabled): Set to true to draw grid lines.
setDrawAxisLines(boolean enabled): Set to true to draw the axis-line next to the line.
setDrawLables(boolean enabled): Set to true to draw the labels of the axes.
4. Modify the axis
setTextColor(int color): Set the color of the axis label.
setTextSize(float size): Sets the text size of the axis labels.
setTypeface (Typeface tf): Set Zhou Biaoqian's Typeface.
setGridColor(int color): Sets the grid line color for this axis.
setGridLineWidth(float width): Sets the width of the grid lines for this axis.
setAxisLineColor(int color): Sets the color of the axes' axes.
setAxisLineWidth(float width): Set the width of the axis line.
enableGridDashedLine(float lineLength, float spaceLength, float phase): Enable gridlines derived in dashed mode, e.g. like this "- - - -".
"lineLength" controls the length of the dashed line segments
"spaceLength" controls the space between the lines
"phase" controls the starting point
of the lines 5. Limit Lines
Both axes support LimitLines to present specific information such as boundaries or limit lines. LimitLines are added to the YAxis to draw in the horizontal direction, and added to the XAxis to draw in the vertical direction. How to add and remove LimitLines by a given axis:
addLimitLines(LimitLine l): Add a new LimitLine to this axis.
removeLimitLine(LimitLine l): Removes the specified LimitLine from this axis.
removeAllLimitLines(): removes all LimitLines.
getLimitLines(): Get all LimitLines
setDrawLimitLineBehindData (booleanenable): Control the z-order between LimitLines and actual data. If set to true, LimitLines are drawn after actualdata, otherwise in front of it. Default: false.
6. Overview
XAxis, YAxis class is a subclass of AxisBase.
The XAxis class is the "data and information container" for all horizontal axes. Each LineChart, BarChart, ScateerChart, CandleStickChart and RadarChart has an XAxis object. The XAxis object presents the data passed to the ChartData object in the form of an ArrayList<String> or String[]("xVals"). Get an instance of XAxis: XAxisxAxis = chart.getXAxis();
The YAxis class is the container for all data and information related to the vertical axis. Each LineChart, BarChart, ScateerChart or CandleStickChart has left and right YAxis objects, respectively on the left and right sides. But RadarChart has only one YAxis. By default, both axes of the chart are enabled and will be plotted. Get an instance of XAxis: YAxisyAxis = chart.getYAxis();
7. Properties:
isDrawAxisLineEnabled(): Returns whether the axis can be drawn (return true/fasle)
setCenterAxisLabels(boolean enabled): Set whether the label is centered
isCenterAxisLabelsEnabled(): Return whether the axis label is centered
setDrawLabels(boolean enabled): Set whether the text can be drawn
isDrawLabelsEnabled( ): Returns whether the axis can draw text
setLabelCount(int count): Sets the number of labels of the axis, when count>25, count=25; when count<2, count=2
setLabelCount(int count, boolean force): Set the number of labels for the axis, this number is not fixed if (force == false), it can only be approximate. If if(force == true), draw exactly the specified number of labels, but this may result in uneven distribution of the axes.
isForceLabelsEnabled(): Returns whether to force labels. Default: false
getLabelCount(): Return the number of labels
setGranularityEnabled(boolean enabled): Set whether the interval can be set
isGranularityEnabled(): Return whether the interval can be set
getGranularity(): Return the axis interval size
setGranularity (float granularity): Set the axis interval size
getLongestLabel(): Returns the longest text of the axis, String type
getFormattedLabel(int index): Returns the formatted text of the axis, String type
setValueFormatter(IAxisValueFormatter f): Sets the format of the axis text
getAxisMaximum(): Returns the value of the axis Maximum value, float type
getAxisMinimum(): return the minimum value of the coordinate axis, float type
setAxisMinimum(float min): set the minimum value of the coordinate axis
setAxisMaximum(float max): set the maximum value of the coordinate axis
calculate(float dataMin, float dataMax) : Calculate the difference between the maximum value and the minimum value of the coordinate axis
setSpaceMin(float mSpaceMin): Set the additional minimum space of the coordinate axis
setSpaceMax(floatmSpaceMax): Set the additional maximum space of the coordinate axis
setAvoidFirstLastClipping(booleanenabled): Set the X-axis first The first and last labels are beyond the screen
setLabelRotationAngle(float angle): Set the direction of the X-axis label text
setPosition(XAxisPosition pos): Set the position of the X-axis label
setZeroLineWidth(float width): Set the width of the first line of the Y-axis
setZeroLineColor(int color): Set the color of the first line of the Y axis
setDrawZeroLine(boolean mDrawZeroLine): Set whether Y displays the first line
setSpaceBottom(float percent): Set the bottom distance
setSpaceTop(float percent): Set the top distance
setStartAtZero(boolean startAtZero): Set whether the Y-axis starts from 0
setInverted(boolean enabled): Set whether the Y-axis is flipped
setDrawTopYLabelEntry(boolean enabled): Set whether to display the top label
setPosition(YAxisLabelPosition pos): Set the Y-axis label position
3. Data (DataSet)
DataSet Class is the base class of all dataset classes, and is a collection of a group or a class of Entry in Chart. It is designed to be logically separate distinct groups of values within the Chart (eg, values for a specific row in a LineChart or values for a specific group of bars in a BarChart).
1. Attribute
setMode(LineDataSet.Mode mode): set mode
CUBIC_BEZIER cubic curve
LINEAR straight line
STEPPED Step
HORIZONTAL_BEZIER Horizontal curve
setCubicIntensity(float intensity): set the degree of curvature of the curve
getColors(): return color (LineChart: polyline; BarChart: column chart, etc.), List<Integer> type
getValueColors(): return text color, List<Integer >type
getColor(): returns the color with index 0, int type
getColor(int index): returns the color with index index, int type
setColors(List<Integer> colors)/setColors(int...colors)/setColors( int[] colors, Context c): set the color
setLabel(String label): set the text
getLabel(): get the text, String type
setHighlightEnabled(boolean enabled): set to true, allows the ChartData object and its DataSets to be highlighted by clicking on it
setValueFormatter (IValueFormatter f): Set the text format
setValueTextColor(intcolor)/setValueTextColors(List<Integer> colors): Set the text color
setValueTypeface(Typeface tf): Set the font of the text
setValueTextSize(float size): Set the font size of the text
setForm(Legend.LegendForm form): Set the size of the shape
setFormLineWidth(float formLineWidth): Set the width of the line
setDrawValues(boolean enabled): Set whether to display text
setVisible(boolean visible): Set whether to display
setDrawFilled(boolean filled): Set whether to fill
setFillAlpha(intalpha): Set fill transparency
setFillColor(int color ): set the fill color
setFillDrawable(Drawable drawable): set the fill drawable
setDrawCircleHole(boolean enabled): set whether it is solid
removeFirst(): remove the first value
removeEntry(int index): remove the value of the subscript index
removeLast(): remove the last value
removeEntryByXValue(float xValue); according to value removal, it is not recommended to use
4. Legend
Legend is usually represented by the form/shape of a label to represent each of multiple entries ( entries ).
The number of entries in the automatically generated legend depends on the number of different colors of the DataSet's labels (over all DataSet objects). Legend's labels depend on the DataSet object used in the chart. If no labels are specified for the DataSet object, the chart will generate them automatically. If multiple colors are used in a DataSet, these colors are classified by only one label description.
1. Attribute
setXOffset(floatxOffset): Set the offset in the X-axis direction
setYOffset(floatyOffset): Set the offset in the Y-axis direction
setTypeface(Typefacetf): Set the font of the text
setTextSize(floatsize): Set the font size of the text
setTextColor (intcolor): Set the text color
setEnabled(booleanenabled): Set whether it is available (simply understood as whether to display)
setEntries(List<LegendEntry> entries); Set the legend, pass the collection of
LegendEntry setExtra(LegendEntry[]entries) Set the legend, pass LegendEntry array
setExtra(List<Integer>colors, List<String> labels) Set the legend, pass the collection of colors and the collection of
LegendEntry setExtra(int[]colors, String[] labels) Set the legend, pass the number of colors and the LegendEntry array
setCustom(LegendEntry [] entries) Set the legend, the gray icon is invisible
setCustom(List<LegendEntry> entries) Set the legend, the gray icon is invisible
setHorizontalAlignment(LegendHorizontalAlignment value) Set the horizontal alignment
setVerticalAlignment(LegendVerticalAlignment value) Set the vertical alignment
setOrientation(LegendOrientation value) Set Direction
setDrawInside(boolean value) Set whether to draw in the chart
setDirection(LegendDirection pos) Set the direction of the text
setForm(LegendForm shape) Set the shape
setFormSize(float size) Set the shape size
setFormLineWidth(float size) Set the line width (when the shape is linear )
setFormLineDashEffect(DashPathEffect dashPathEffect) Set the line track
setXEntrySpace(float space) Set the legend horizontal spacing
setYEntrySpace(float space) Set the legend vertical spacing
setFormToTextSpace(float space) Set the legend and text spacing
setWordWrapEnabled(boolean enabled) Set whether the legend recreate a row
Properties and methods of MPAndroidChart
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=326196188&siteId=291194637
Recommended
Ranking