forked from PhilJay/MPAndroidChart
-
Notifications
You must be signed in to change notification settings - Fork 0
Getting Started
Philipp Jahoda edited this page Mar 5, 2015
·
32 revisions
Setup
For using a LineChart, BarChart, ScatterChart, CandleStickChart, PieChart or RadarChart , define it in .xml:
<com.github.mikephil.charting.charts.LineChart
android:id="@+id/chart"
android:layout_width="match_parent"
android:layout_height="match_parent" />And then retreive it from your Activity, Fragment or whatever:
LineChart chart = (LineChart) findViewById(R.id.chart);or create it in code (and then add it to a layout):
LineChart chart = new LineChart(Context);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativeLayout);
rl.add(chart);Refreshing
-
invalidate(): Calling this method on the chart will redraw (refresh) it.
Logging
-
setLogEnabled(boolean enabled): Setting this to true will activate chart logcat output.
General Chart Styling
Here are some general styling methods you can directly use on the chart:
-
setBackgroundColor(int color): Sets the background color that will cover the whole chart-view. In addition, a background-color can be set via.xmlin the layout file. -
setDescription(String desc): Set a description text that appears in the bottom right corner of the chart. -
setDescriptionTypeface(Typeface t): Sets theTypefaceused for drawing the description text. -
setNoDataTextDescription(String desc): Sets the text that should appear if 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.
Useful getter methods
-
getData(): Will return the data object you set for the chart. -
getViewPortHandler(): Will returnViewPortHandlerobject of the chart that contains information about the charts size and bounds (offsets, content-area). -
getRenderer(): Returns the mainDataRendererthat is responsible for drawing the chart data. -
getCenter(): Returns the center point of the whole chart-view. -
getCenterOffsets(): Returns the center point of the chart drawing-area. -
getAverage(): Returns the average value across all values the chart holds. -
getPercentOfTotal(float value): Returns the percentage the provided value makes up of the total value-sum inside the chart. -
getValueCount(): Returns the total number of values the chart holds. -
getValueSum(): Returns the sum of all values inside the chart. -
getYMin(): Returns lowest value the chart holds. -
getYMax(): Returns biggest value the chart holds.