This is a migrated thread and some comments may be shown as answers.

Line Series Example not working as per video

15 Answers 159 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kuria
Top achievements
Rank 1
Kuria asked on 02 Jul 2014, 09:29 PM
Hello again.



I decided to replicate line for line the example provided here https://www.youtube.com/watch?v=JStf9gekJCM  so as to see if i could get a working example.

A number of things happened.
1. in the video he uses code like RadCartesianChartView chartView = new RadCartesianChartView(this.getBaseContext());  replicating this resulted in an error and the program would not run. I had to use just "this" instead of this.getBaseContext()

2. The example does not run unless you move chartView.getSeries().add(lineSeries);  as the last line in the code. placing it where it is shown in the video results in the example crashing. Not sure whether its an issue with my version.

3. When the example runs, it shows the graph but within the graph there are 4 lines stating a)NoHorizontalAxis, b) NoVerticalAxis , c)NoSeries and d) NoData. This is clearly not true since it is displaying the graph. I've attached a screenshot along with the code i'm using.

I'm using Android Studio (Beta) 0.8.1  and appcompat ver 7.19 along with corresponding support ActionBar 
Unfortunately I'm unable to upload the screenshot even though its only 97kb. The uploader complains...not sure why. 
-----code----
---Gradle Dependencies

compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.android.support:support-v4:18.0.+'
    compile files('libs/socialauth-4.3.jar')
    compile files('libs/bugsense-3.5.jar')
    compile files('libs/httpmime-4.2.5.jar')
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile files('libs/socialauth-4.3.jar')
    compile (name:'Common-2014.2.0618-trialRelease', ext:'aar')
    compile (name:'Primitives-2014.2.0618-trialRelease', ext:'aar')
    compile (name:'Chart-2014.2.0618-trialRelease', ext:'aar')


package  com.mycompany.myBusiness;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.ViewGroup;

import com.mycompany.myBusiness.R;
import com.telerik.widget.chart.engine.databinding.DataPointBinding;
import com.telerik.widget.chart.visualization.cartesianChart.RadCartesianChartView;
import com.telerik.widget.chart.visualization.cartesianChart.axes.CategoricalAxis;
import com.telerik.widget.chart.visualization.cartesianChart.axes.LinearAxis;
import com.telerik.widget.chart.visualization.cartesianChart.series.categorical.LineSeries;
import java.util.ArrayList;
import java.util.List;


/**
 * Created by KuriaNdungu on 01/07/2014.
 */
public class activity_daily_log_chart extends ActionBarActivity {

   boolean blnSufficientDataForChart=false;
    CategoricalAxis horizontalAxis;
    LinearAxis verticalAxis;
    List<MonthResults> monthResults;
    LineSeries lineSeries;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_daily_log_charts);
        initData();
        RadCartesianChartView chartView = new RadCartesianChartView(this);

        ViewGroup rootView =(ViewGroup) findViewById(R.id.container);
        rootView.addView(chartView);

        lineSeries = new LineSeries(this);
        lineSeries.setCategoryBinding(new DataPointBinding() {
            @Override
            public Object getValue(Object o) throws IllegalArgumentException {
                return ((MonthResults)o).getMonth();
            }
        });

        lineSeries.setValueBinding(new DataPointBinding() {
            @Override
            public Object getValue(Object o) throws IllegalArgumentException {
                return ((MonthResults)o).getResult();
            }
        });

        lineSeries.setData(this.monthResults);
        CategoricalAxis horizontalAxis = new CategoricalAxis(this);
        LinearAxis verticalAxis = new LinearAxis(this);

        chartView.setVerticalAxis(verticalAxis);
        chartView.setHorizontalAxis(horizontalAxis);
        chartView.getSeries().add(lineSeries);


    }

    private void initData() {
      monthResults=new ArrayList<MonthResults>();
        monthResults.add(new MonthResults("Jan",24));
        monthResults.add(new MonthResults("Feb",20));
        monthResults.add(new MonthResults("Mar",15));
        monthResults.add(new MonthResults("Apr",17));
        monthResults.add(new MonthResults("May",21));
        monthResults.add(new MonthResults("Jun",28));
        monthResults.add(new MonthResults("Jul",32));
        monthResults.add(new MonthResults("Aug",48));
        monthResults.add(new MonthResults("Sep",51));
        monthResults.add(new MonthResults("Oct",42));
        monthResults.add(new MonthResults("Nov",57));
        monthResults.add(new MonthResults("Dec",60));

    }


}

--------------monthResults Class -----------------------
package  com.mycompany.myBusiness;

/**
 * Created by KuriaNdungu on 02/07/2014.
 */
public class MonthResults {
    private String month;
    private double result;
    public MonthResults(String month,double result){
        this.setMonth(month);
        this.setResult(result);
    }

    public String getMonth() {
        return month;
    }

    public void setMonth(String month) {
        this.month = month;
    }

    public double getResult() {
        return result;
    }

    public void setResult(double result) {
        this.result = result;
    }
}




























15 Answers, 1 is accepted

Sort by
0
Deyan
Telerik team
answered on 03 Jul 2014, 07:13 AM
Hi Kuria,

Thanks for writing.

I would like to inform you that we have addressed these shortcomings and they are available in an update that is live from yesterday.

Please go to the downloads section in your Telerik Account and check it out. The version is 2014.2.702.

The videos that you have found are related to the Beta release so some code samples in them might be outdated. We are working on updating this as well.

Let us know if you have additional questions.

Regards,
Deyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kuria
Top achievements
Rank 1
answered on 03 Jul 2014, 07:24 AM
Thank you. I'll check them out and revert. 
0
Deyan
Telerik team
answered on 03 Jul 2014, 08:29 AM
Hi Kuria,

We will consider this thread closed for now.

Let us know should you have additional questions or need assistance.

Regards,
Deyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kuria
Top achievements
Rank 1
answered on 03 Jul 2014, 09:47 PM
I'm sorry to report that the issue of NoHorizontalAxis,NoVerticalAxis,NoSeries and NoData persists. It still shows up even though the chart is being drawn.
I'm using the latest controls downloaded on 3rd Jul 2014.
0
Kuria
Top achievements
Rank 1
answered on 04 Jul 2014, 08:40 AM
Hello attached is the screenshot for the issue explained above. Also my dependencies

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:19.1.0'
    compile 'com.android.support:support-v4:18.0.+'
    compile files('libs/socialauth-4.3.jar')
    compile files('libs/bugsense-3.5.jar')
    compile files('libs/httpmime-4.2.5.jar')
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile files('libs/socialauth-4.3.jar')
    compile (name:'Chart-2014.2.702-trialRelease', ext:'aar')
    compile (name:'Primitives-2014.2.702-trialRelease', ext:'aar')
    compile (name:'Common-2014.2.702-trialRelease', ext:'aar')
}
0
Accepted
Antony Jekov
Telerik team
answered on 04 Jul 2014, 12:18 PM
Hello Kuria,

I carefully reviewed your code and I cannot find any issues with it. It works as expected on our side after literal copy-paste from your first example.

As far as we can tell here you are adding two series in your chart. The first one, however, seems to not be initialized with a data source. Can you please verify that this is the case and if not, modify the project we are attaching here in a way that reproduces the glitch and resend it to us by opening a new support ticket or simply pasting the code here? We will take a look at what's going on at that point.

Please take a look at the attached project and feel free to modify it so that it reproduces the case.

Looking forward to your reply.

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Kuria
Top achievements
Rank 1
answered on 04 Jul 2014, 01:02 PM
Thanks for taking time to reply.
It seems the problem is on my end because I ran your example and it was completely fine. The NoHorizontalAxis etc issue is gone.
I'll look dig into your code and compare with mine to see where i'm going wrong. I suspect its the second series as suggested in your last post.

Thanks again.
0
Deyan
Telerik team
answered on 04 Jul 2014, 01:06 PM
Hi Kuria,

Thanks for writing back.

Good to hear that you've managed to resolve the case.

Let us know should you have additional questions.

Regards,
Deyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jay
Top achievements
Rank 1
answered on 09 Jul 2014, 01:15 PM
hi,

is there any touch functionality like single tap and double tab with zoom controls

please let me know

regards,
jay
0
Deyan
Telerik team
answered on 10 Jul 2014, 06:50 AM
Hello Jay,

Thanks for writing and for your question.

You can use double-tap to zoom-out to the initial zoom level.

Is that what you're looking for?

Regards,
Deyan
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jay
Top achievements
Rank 1
answered on 10 Jul 2014, 06:57 AM
hi,

yes , how i can implement it and on tap of bar or line i want to divert user to some fragment or activity

regards,
jay
0
Antony Jekov
Telerik team
answered on 14 Jul 2014, 07:36 AM
Hello Jay,

Thanks for writing.

If you want to hook up to the tap events and add some custom logic to them, all you need to do is to extend the pan and zoom behavior.

I would suggest something like this:

ChartPanAndZoomBehavior behavior = new CustomPanAndZoomBehavior();
chart.getBehaviors().add(behavior);

And the custom class:

private class CustomPanAndZoomBehavior extends ChartPanAndZoomBehavior {
    @Override
    public boolean onTap(MotionEvent e) {
        // Your custom logic here
 
        return super.onTap(e);
    }
 
    @Override
    public boolean onDoubleTap(MotionEvent event) {
        // Your custom logic here
 
        return super.onDoubleTap(event);
    }
}

Please let me know if this answers your question. I hope this is what you need.

All best and happy coding!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Goddess
Top achievements
Rank 1
answered on 13 Dec 2015, 06:44 AM
why do i have this.getbasecontext problem ?
0
Goddess
Top achievements
Rank 1
answered on 13 Dec 2015, 06:44 AM
and what is the viewgroup ? is it refering to my layout ?
0
Todor
Telerik team
answered on 16 Dec 2015, 04:45 PM
Hello,

RadChartView, just like any other View needs a context in order to be initialized. Depending on the place where you are executing the code you may need to use different methods to get the context. For example inside an Activity, you can use this, inside a Fragment, you can use getActivity(). If you are curious to know more about the context in Android, you can have a look at this article.

As to the ViewGroup, yes it is the main layout, or any other layout that is visible. The idea here is to use the ViewGroup's AddView method to add the chart so that it become part of your layout.

You can also have a look at our online documentation which contains more examples for the usage of RadChartView.

Regards,
Todor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Kuria
Top achievements
Rank 1
Answers by
Deyan
Telerik team
Kuria
Top achievements
Rank 1
Antony Jekov
Telerik team
Jay
Top achievements
Rank 1
Goddess
Top achievements
Rank 1
Todor
Telerik team
Share this question
or