EzDev.org

MPAndroidChart

MPAndroidChart - A powerful Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, dragging and animations.


MPAndroidChart remove legend

I am using MPAndroid lib and i want to remove the x-Values List in the top right corner of the Pie Chart, how can i do this ?


Source: (StackOverflow)

Hide point views from MPChart LineChart

I'd like to hide (or better, to not draw) the plot points upon the drawn line.

Here is a screenshot: enter image description here

Have you got any suggestion on how to do it? I read the documentation but I found nothing useful for this.

Thanks in advance! Bye!


Source: (StackOverflow)

Custom view of Limit Line in MPAndroidChart

Is it possible to replace LimitLine with custom layout? So it looks something like this:

enter image description here

I see few solutions for that:

  1. Perhaps there're methods inside library for customizations like this, are there any?
  2. Get coordinates of TextView where the value is stored and add custom layout on that place. But how can I reach this TextView?

Perhaps someone faced that problem. Please share your experience.


EDIT: latest partial solution

After long searching of solution I came up to adding custom view programmatically by coordinates of Limit Line.

General layout of screen as follows:

enter image description here

Coordinates are calculated pretty straightforward. X is known from Chart coordinates and Y:

Y = ((max - lastValue) * height) / ((max + min) + y)

So at this point I basically know the position I need. Although I'm not sure it's right due to parent ScrollView.

The next step is to add custom layout at those coordinates (x, y)

enter image description here

And here comes the new problem. I tried to add view to top RelativeLayout. It is added but it doesn't move together with ScrollView. Therefore its needed to add that view exactly on Chart. Look how I tried to achieve this:

private void addCustomLayoutOnLimitLine(final double lastValue) {

    mChart.post(new Runnable() { //check location when view is created
        public void run() {
            int[] chartLocationOnScreen = new int[2];
            mChart.getLocationOnScreen(chartLocationOnScreen);

            int x = chartLocationOnScreen[0];
            int y = chartLocationOnScreen[1];

            int width = mChart.getWidth();
            int height = mChart.getHeight();


            double max = mChart.getYMax();
            double min = mChart.getYMin();

            int limitXPoint = x + width;
            int limitYPoint = (int) ((((max - lastValue) * height) / (max + min))+ y);



            LayoutInflater inflater = (LayoutInflater)   getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            RelativeLayout rlValue = (RelativeLayout) inflater.inflate(R.layout.item_chart_value, null);
            TextView tvValue = (TextView) rlValue.findViewById(R.id.tv_value);
            tvValue.setText(String.valueOf(lastValue));

            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
            params.leftMargin = limitXPoint - 100;
            params.topMargin = limitYPoint;
            mChart.addView(rlValue, params); //this doesn't seem to be working
            rlValue.bringToFront();
        }
    });
}

Perhaps I should reach the parent layout of Chart and inflate my custom layout there. But how?


EDIT 2: added custom view over chart but can't find proper location due to scroll view

Now the situation looks like that :

enter image description here

Perhaps I'm somewhere wrong in calculations. But at least that View changes its position with the new value although it never hits at right coordinations.

private void addCustomLayoutOnLimitLine() {
    if (mChart == null){
        return;
    }

    mChart.post(new Runnable() { //check location when view is created
        public void run() {
            int[] chartLocationOnScreen = new int[2];
            mChart.getLocationOnScreen(chartLocationOnScreen);

            int xChart = chartLocationOnScreen[0];
            int yChart = chartLocationOnScreen[1];

            int chartWidth = mChart.getWidth();
            int chartHeight = mChart.getHeight();

            int rootWidth = rlSvContent.getWidth();
            int rootHeight = rlSvContent.getHeight(); //this is height of ScrollView

            int infoWidth = llInfoWrapper.getWidth(); //width of info panel ABOVE chart
            int infoHeight = llInfoWrapper.getHeight();

            double lastValue = mSingleAsset.getGraph().get(mSingleAsset.getGraph().size() - 1).getValue();
            double maxValue = mChart.getYMax();
            double minValue = mChart.getYMin();

            int limitXPoint = (rootWidth - chartWidth) / 2 + chartWidth;
            int limitYPoint = (int) ((maxValue - lastValue) * chartHeight/(maxValue - minValue)) + yChart;

            tvCustomValue.setText(SingleAsset.round((float) lastValue, 2).toString()); //display last value on custom view

            RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.leftMargin = limitXPoint - xChart - 50; //move custom view. xChart = right margin value and 50 is taken to count values bar to the right of chart
            params.topMargin = limitYPoint;
            rlCustomValue.setLayoutParams(params);
            rlCustomValue.bringToFront();
            rlCustomValue.invalidate();
        }
    });
}

Source: (StackOverflow)

Remove all slice text from Pie Chart (ios-charts/mpandroidchart)

I know the method for removing the x-values but how do I remove the y-values. I basically don't want ANY text on my Pie Chart.

The image shows the current-state with the 80.0 and 20.0 labels on top of the pie chart. pie chart


Source: (StackOverflow)

java.lang.RuntimeException: Parcelable encountered IOException writing serializable object in Android passing ArrayList object

I want to pass my ArrayList object to another activity, using a DataWrapper that implements Serializable.
I followed the answer provided here: Pass arraylist of user defined objects to Intent android.
I am starting the another Activity from MPAndroidChart library PieChart's OnChartGestureListener(). This is how I passed my ArrayList object threadList:

mChart.setOnChartGestureListener(new OnChartGestureListener() {
@Override
public void onChartSingleTapped(MotionEvent me) {
    Intent intent = new Intent(MainActivity.this, TextersSmsActivity.class);
    intent.putExtra("threadList", new DataWrapper(threadList));
    MainActivity.this.startActivity(intent);
}
//.....
}

I implemented the DataWrapper class like this:

public class DataWrapper implements Serializable {
private static final long serialVersionUID = 100L;
private ArrayList<OneThread> threadList;

   public DataWrapper(ArrayList<OneThread> threadList) {
      this.threadList = threadList;
   }

   public ArrayList<OneThread> getThreadList() {
      return threadList;
   }
}

And getting the Parcelable encountered IOException writing serializable object error. Here is my Logcat:

11-29 21:12:09.919: E/MessageQueue-JNI(21550): java.lang.RuntimeException: Parcelable encountered IOException writing serializable object (name = com.myproj.DataWrapper)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.os.Parcel.writeSerializable(Parcel.java:1316)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.os.Parcel.writeValue(Parcel.java:1264)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.os.Parcel.writeArrayMapInternal(Parcel.java:618)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.os.Bundle.writeToParcel(Bundle.java:1692)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.os.Parcel.writeBundle(Parcel.java:636)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.content.Intent.writeToParcel(Intent.java:7013)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.ActivityManagerProxy.startActivity(ActivityManagerNative.java:2076)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.Instrumentation.execStartActivity(Instrumentation.java:1419)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.Activity.startActivityForResult(Activity.java:3424)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.Activity.startActivityForResult(Activity.java:3385)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.Activity.startActivity(Activity.java:3627)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.Activity.startActivity(Activity.java:3595)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.myproj.MainActivity$11.onChartSingleTapped(MainActivity.java:967)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.github.mikephil.charting.listener.PieRadarChartTouchListener.onSingleTapUp(PieRadarChartTouchListener.java:89)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.GestureDetector.onTouchEvent(GestureDetector.java:595)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.github.mikephil.charting.listener.PieRadarChartTouchListener.onTouch(PieRadarChartTouchListener.java:40)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.github.mikephil.charting.charts.PieRadarChartBase.onTouchEvent(PieRadarChartBase.java:56)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.View.dispatchTouchEvent(View.java:7706)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2068)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1515)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.app.Activity.dispatchTouchEvent(Activity.java:2458)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.support.v7.app.ActionBarActivityDelegateICS$WindowCallbackWrapper.dispatchTouchEvent(ActionBarActivityDelegateICS.java:268)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2016)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.View.dispatchPointerEvent(View.java:7886)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3947)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3518)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3575)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3442)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3411)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3419)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3392)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5532)
11-29 21:12:09.919: E/MessageQueue-JNI(21550):  at android.view.ViewRootImpl.doP

I followed the answer (to pass array list objects) in the link above but getting the Error, what is causing the error and how to remove it?


Source: (StackOverflow)

MPAndroidChart - Change message "No chart data available"

There is any way to change the message "No chart data available" when the chart is not populated?

Edit: Found the answer

chart.setNoDataText("Description that you want");

Source: (StackOverflow)

Android charting libraries [closed]

I am trying to find a fast and reliable charting library. After some searching, I found 4 libraries: AChartEngine, WilliamChart, HelloCharts and AndroidPlot. I need some up to date feedback about the performance and the stability of these libraries because all the information I could find was outdated.


Source: (StackOverflow)

How to hide legends and axis in MPAndroidChart?

Is their any possibility to hide all rounded items from this picture.

enter image description here

I have used the following code,

public void setDataList(List<HorizontalBarChartData> dataList, Resources resources) {

    ArrayList<String> categories = new ArrayList<String>();
    ArrayList<BarEntry> values = new ArrayList<BarEntry>();
    ArrayList<BarDataSet> dataSets = new ArrayList<BarDataSet>();
    BarDataSet set1;
    for (int i = 0; i < dataList.size(); i++) {
        categories.add(dataList.get(i).getName());
        values.add(new BarEntry(dataList.get(i).getValue(), i));
    }

    /*set1 = new BarDataSet(values, "Income, Expense, Disposable Income");*/
    set1 = new BarDataSet(values, "Category 1, Category 2, Category 3");
    set1.setBarSpacePercent(35f);
    set1.setColors(new int[]{resources.getColor(R.color.cyan_blue), resources.getColor(R.color.vermilion_tint), resources.getColor(R.color.sea_green)});
    dataSets.add(set1);

    BarData data = new BarData(categories, dataSets);
    data.setValueTextSize(10f);

    horizontalBarChart.setData(data);
}

Update

How to hide rounded part from this image?

enter image description here


Source: (StackOverflow)

mpandroidchart - How can I avoid the repeated values in Y-Axis?

I want to avoid the repeated values and the -0 values in Y-Axis, avoiding the image situation.

I have these ideas to solve this, but any solution:

  1. Limit the zoom before having repeated values in YAxis, therefore stop the infinite zoom-in on the chart
  2. Get the YAxis values and remove the duplicate values.

YAxis with duplicate values


Source: (StackOverflow)

Failed to resolve: com.github.PhilJay:MPAndroidChart:v2.1.4

I am using MPAndroidChart libarary in android studio.But when i am trying to sync gradle which given an error as below image. Gradle text is here to compile MPAndroidChart libarary.

compile 'com.github.PhilJay:MPAndroidChart:v2.1.4'

Error screenshot

Please help to resolve this problem. Thanks in advance


Source: (StackOverflow)

How to format values inside MPAndroidChart?

2 Questions about the MPAndroidChart library. All my yvalues are integers, but displayed as Decimals. How can I get them displayed as integers (without the digits)? How can I prevent that the ylabels are also shows as decimals? I know there is a setFormatter for the yvalues, just don't understand how to use...


Source: (StackOverflow)

View outside bounds not drawing properly

I'm drawing a tooltip after clicking inside a custom bar chart (created with MPAndroidChart). The view hierarchy is as follows

<LinearLayout>
     <TextView text=Move & Max Pain/>
     <RelativeLayout with 2 textviews>
     <chart
       clipToChildren=false
       clipToPadding=false
     />
</LinearLayout>

While the View is inside the Chart or its inmediate sibling, everthing looks good. But the moment it collides with its sibling, the tooltip is truncated

enter image description here

Using HierarchyViewer I can see that the content is present, but it's not drawn.

In order to get the clipping, I'm using this code inside draw

    @Override
  public void draw(Canvas canvas, float posx, float posy) {
    // take offsets into consideration
    posx += getXOffset();
    posy += getYOffset();

    canvas.save();

    // translate to the correct position and draw
    canvas.translate(posx, posy);

    Rect clipBounds = canvas.getClipBounds();
    clipBounds.inset(0, -getHeight());
    canvas.clipRect(clipBounds, Region.Op.INTERSECT);

    draw(canvas);
    canvas.translate(-posx, -posy);

    canvas.restore();
  }

If I change Op to Region.Op.Replace, the tooltip is draw correctly but it replaces the Toolbar content, instead of scrolling under it.

enter image description here


Source: (StackOverflow)

How to remove description from chart in MPAndroidChart?

I am using MPAndroidChart.

How can I remove the description from PieChart? I can remove the Legend with chart.setDrawLegend(false), but I couldn't find anything regarding the chart description in the documentation.


Source: (StackOverflow)

How to hide drawn values in MPAndroidChart?

I need to hide the value above bars in MPAndroidChart for barchart. I have tried all the methods available in it , but could not find the solution.


Source: (StackOverflow)

How MPAndroidChart display all xaxis values

I'm developing some chart features using MPAndroidChart library.

Is there any way to display all the xaxis values I added? Seems that the library will auto calculate on xaxis, some of values will be hidden. ex. display date: 05-17 05-17 05-15 .... the same day 05-17 will not shown.

thanks!


Source: (StackOverflow)