Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8497073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:01:26+00:00 2026-06-11T00:01:26+00:00

I need to draw charts in my application. For that i use RGraph (

  • 0

I need to draw charts in my application. For that i use RGraph ( http://www.rgraph.net/ ) ; it allows to draw interactive charts with Javascript. I put my javascript code in a HTML document in assets of application, and i call it from a fragment in a ViewPager.

Here is the HTML and javascript code :

<meta http-equiv="content-type" content="text/html; charset=utf-8" />

<html>
<head>    
    <script src="./libraries/RGraph.common.core.js" ></script>
    <script src="./libraries/RGraph.common.dynamic.js" ></script>
    <script src="./libraries/RGraph.common.tooltips.js" ></script>
    <script src="./libraries/RGraph.common.effects.js" ></script>
    <script src="./libraries/RGraph.pie.js" ></script>
    </head>
<body background="../transparent.png"> 

    <canvas id="cvs" width="420" height="400">[No canvas support]</canvas>
           
    <script>
    
        function CreateGradient (obj, color)
        {
            return RGraph.RadialGradient(obj, 200, 150, 95, 200, 150, 125, color, color)
        }
        
        function isCanvasSupported(){
            var test_canvas = document.createElement("canvas");
            var canvascheck=(test_canvas.getContext) ? true : false ;           
          return canvascheck;
        }
        window.onload = function ()
        {
            if(isCanvasSupported)
               DrawPieChart();
            else
               document.write("hheheheheh");
        }
        
        
        function DrawPieChart ()
        {
                    var canvas = document.getElementById('cvs');
            var ctx = canvas.getContext('2d');
            var pie = new RGraph.Pie('cvs', [2,3,6,7,82]);
            pie.Set('chart.colors', [
                                     CreateGradient(pie, '#580600'),
                                     CreateGradient(pie, '#AEAEAE'),
                                     CreateGradient(pie, '#860100'),
                                     CreateGradient(pie, '#C7C7C7'),
                                     CreateGradient(pie, '#A70000')
                                    ]);
            pie.Set('chart.labels.sticks', true);
            pie.Set('chart.labels.sticks.length', 5);
            pie.Set('chart.tooltips', ['Autres',
            'Italie',
            'Royaume-Uni',
            'Espagne',
            'France']);
            pie.Set('chart.labels', ['2%','3%','6%','7%','82%']);
            pie.Set('chart.radius', 150);
            pie.Set('chart.shadow', true);
            pie.Set('chart.shadow.offsetx', 0);
            pie.Set('chart.shadow.offsety', 0);
            pie.Set('chart.shadow.blur', 25);
            pie.Draw();        
        }
    </script>
</body>
</html>

and here is the code of a fragment :

@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        mWebView = (WebView)getActivity().findViewById(R.id.group_fragment_one_webView);
        mWebView.setFocusable(false);
        mWebView.loadUrl("file:///android_asset/graphs/graph1.html");
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.getSettings().setDefaultZoom(ZoomDensity.FAR);
        mWebView.getSettings().setDefaultFontSize(24);
        mWebView.getSettings().setBuiltInZoomControls(false);
        mWebView.setBackgroundColor(0);
        mWebView.setHorizontalScrollBarEnabled(false);
        mWebView.setVerticalScrollBarEnabled(false);
        mWebView.getSettings().setSupportZoom(false);
        mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);

        String TAG = "HTML 5";
        WebSettings ws = mWebView.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setAllowFileAccess(true);


        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.ECLAIR) {
            try {
                Method m1 = WebSettings.class.getMethod("setDomStorageEnabled", new Class[]{Boolean.TYPE});
                m1.invoke(ws, Boolean.TRUE);

                Method m2 = WebSettings.class.getMethod("setDatabaseEnabled", new Class[]{Boolean.TYPE});
                m2.invoke(ws, Boolean.TRUE);

                Method m3 = WebSettings.class.getMethod("setDatabasePath", new Class[]{String.class});
                m3.invoke(ws, "/data/data/" + getActivity().getApplicationContext().getPackageName() + "/databases/");

                Method m4 = WebSettings.class.getMethod("setAppCacheMaxSize", new Class[]{Long.TYPE});
                m4.invoke(ws, 1024*1024*8);

                Method m5 = WebSettings.class.getMethod("setAppCachePath", new Class[]{String.class});
                m5.invoke(ws, "/data/data/" + getActivity().getApplicationContext().getPackageName() + "/cache/");

                Method m6 = WebSettings.class.getMethod("setAppCacheEnabled", new Class[]{Boolean.TYPE});
                m6.invoke(ws, Boolean.TRUE);

                Log.d(TAG, "Enabled HTML5-Features");
            }
            catch (NoSuchMethodException e) {
                Log.e(TAG, "Reflection fail", e);
            }
            catch (InvocationTargetException e) {
                Log.e(TAG, "Reflection fail", e);
            }
            catch (IllegalAccessException e) {
                Log.e(TAG, "Reflection fail", e);
            }

        }


        mTextView1 = (TextView)getActivity().findViewById(R.id.group_fragment_one_textview1);
        mTextView1.setText(getActivity().getResources().getString(R.string.group_fragment_one_text1));
        Spannable spanSize = new SpannableString(mTextView1.getText());
        spanSize.setSpan(new RelativeSizeSpan(2.0f),
                0,
                mTextView1.getText().toString().indexOf("millions"),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        mTextView1.setText(spanSize);
        Spannable colorSpan = new SpannableString(mTextView1.getText());        
        colorSpan.setSpan(new ForegroundColorSpan(getActivity().getResources().getColor(R.color.red_ribbon)),
                0,
                mTextView1.getText().toString().indexOf("millions"),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mTextView1.setText(colorSpan);
        mTextView1.setTypeface(Utils.getTextFont(getActivity().getApplicationContext()));


        mTextView2 = (TextView)getActivity().findViewById(R.id.group_fragment_one_textview2);
        mTextView2.setText(getActivity().getResources().getString(R.string.group_fragment_one_text2));
        spanSize = new SpannableString(mTextView2.getText());
        spanSize.setSpan(new RelativeSizeSpan(2.0f),
                0,
                mTextView2.getText().toString().indexOf("du chiffre"),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

        mTextView2.setText(spanSize);
        colorSpan = new SpannableString(mTextView2.getText());        
        colorSpan.setSpan(new ForegroundColorSpan(getActivity().getResources().getColor(R.color.red_ribbon)),
                0,
                mTextView2.getText().toString().indexOf("du chiffre"),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mTextView2.setText(colorSpan);
        mTextView2.setTypeface(Utils.getTextFont(getActivity().getApplicationContext()));


        super.onActivityCreated(savedInstanceState);
    }

It works fine on the emulator and on the Eclipse browser… But when I want to see it on a smartphone i have a bug with Canvas. sometimes the chart is correctly displayed, sometimes "No canvas support" is displayed. In the ViewPager, only the fragment n, the fragment n-1 and n+1 are simultaneously instantiated. Other fragments are instantiated when the user scroll on another fragment. So each time the user scroll, a HTML is loaded. and sometimes the canvas is supported, sometimes not…

I tried to get the support of canvas in javascript, but it always returns that the canvas is supported whereas it’s not true…

Any idea ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T00:01:28+00:00Added an answer on June 11, 2026 at 12:01 am

    Try to load the webview on the onResume() method:

    @Override
    public void onResume(){
    
        mWebView.loadUrl("file:///android_asset/graphs/graph1.html");
        super.onResume();
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a javascript (HTML4/5) based library to draw a line chart that has
while developing an Android application that uses Rickshaw to draw some charts, I encountered
I need to draw vertical and horizontal rectangle / bands (like in Gantt charts)
Currently, I am working on a web application that uses draw2d library to draw
I need to draw charts using c# and WPF. I did some work using
I am using excel to draw charts from c#, but i need the chart
Now I'm doing a project which need draw multiple pie charts with text. Can
I need to draw some simple network topology charts, suggestions of some good tools
I am doing some stuff with gwt, Now i need to draw charts. Actually
I need to draw a chart in Jasper iReport that can sum the results

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.