Line Series Example not working as per video

16 posts, 1 answers
  1. Kuria
    Kuria avatar
    11 posts
    Member since:
    Jun 2014

    Posted 02 Jul 2014 Link to this post

    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;
        }
    }




























  2. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 03 Jul 2014 Link to this post

    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.

     
  3. DevCraft banner
  4. Kuria
    Kuria avatar
    11 posts
    Member since:
    Jun 2014

    Posted 03 Jul 2014 in reply to Deyan Link to this post

    Thank you. I'll check them out and revert. 
  5. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 03 Jul 2014 Link to this post

    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.

     
  6. Kuria
    Kuria avatar
    11 posts
    Member since:
    Jun 2014

    Posted 03 Jul 2014 in reply to Kuria Link to this post

    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.
  7. Kuria
    Kuria avatar
    11 posts
    Member since:
    Jun 2014

    Posted 04 Jul 2014 in reply to Kuria Link to this post

    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')
    }
  8. Answer
    Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 04 Jul 2014 Link to this post

    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.

     
  9. Kuria
    Kuria avatar
    11 posts
    Member since:
    Jun 2014

    Posted 04 Jul 2014 in reply to Antony Jekov Link to this post

    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.
  10. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 04 Jul 2014 Link to this post

    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.

     
  11. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 09 Jul 2014 Link to this post

    hi,

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

    please let me know

    regards,
    jay
  12. Deyan
    Admin
    Deyan avatar
    2039 posts

    Posted 10 Jul 2014 Link to this post

    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.

     
  13. Jay
    Jay avatar
    18 posts
    Member since:
    May 2014

    Posted 10 Jul 2014 in reply to Deyan Link to this post

    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
  14. Antony Jekov
    Admin
    Antony Jekov avatar
    88 posts

    Posted 14 Jul 2014 Link to this post

    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.

     
  15. Goddess
    Goddess avatar
    2 posts
    Member since:
    Dec 2015

    Posted 13 Dec 2015 in reply to Deyan Link to this post

    why do i have this.getbasecontext problem ?
  16. Goddess
    Goddess avatar
    2 posts
    Member since:
    Dec 2015

    Posted 13 Dec 2015 in reply to Goddess Link to this post

    and what is the viewgroup ? is it refering to my layout ?
  17. Todor
    Admin
    Todor avatar
    778 posts

    Posted 16 Dec 2015 Link to this post

    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
Back to Top
DevCraft banner