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 6069391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:49:03+00:00 2026-05-23T09:49:03+00:00

I’m experiencing problem creating a graph. The data for the graph is coming from

  • 0

I’m experiencing problem creating a graph. The data for the graph is coming from database as a HashMap. Following is my code:

public void onModuleLoad()
{

    Runnable onLoadCallback = new Runnable() 
    {
        public void run() 
        {
            AbstractDataTable data = createLineTable();
            Options options = createLineOptions();
            LineChart line = new LineChart(data, options);
            vPanelWithGraph.add(line);
            vPanelWithGraph.add(closeGraphPopUp);
    };
    VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);
    popUpGraph.add(vPanelWithGraph);
}

private LineChart.Options createLineOptions() 
{
    Options options = Options.create();
    options.setWidth(400);
    options.setHeight(240);
    options.setTitle("Graph Name");
    return options;
}

private AbstractDataTable createLineTable() 
{       
    DataTable data = DataTable.create();
    data.addColumn(ColumnType.STRING, "Date");
    data.addColumn(ColumnType.NUMBER, "Number");

    HashMap<String,String> map = getDateAndWarningCount();
    data.addRows(2);

    String [] arrDate = new String [2];
    int  [] arrWarCount = new int [2];
    int i=0;
    Iterator it = map.entrySet().iterator();

    while (it.hasNext()) 
    {
        Map.Entry pairs = (Map.Entry)it.next();
        System.out.println(pairs.getKey() + " = " + pairs.getValue());
        arrDate[i]=""+pairs.getKey();
        arrWarCount[i]=Integer.parseInt((String)pairs.getValue());
        i++;
    }
    data.setValue(0, 0, arrDate[0]);// row column
    data.setValue(0, 1, 5);

    data.setValue(1, 0, arrDate[1]);
    data.setValue(1, 1, 6);

    return data;
}

private HashMap<String,String> getDateAndWarningCount()
{
    HashMap<String,String> map = null;
    SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
    AsyncCallback<HashMap<String,String>>  callback = new AsyncCallback<HashMap<String,String>>()
    {
        @Override
        public void onFailure(Throwable caught) 
        {}

        @Override
        public void onSuccess(HashMap<String,String> result)
        {
            map  = (HashMap<String,String>)result;
        }
    };
    service.getHashMapValues(callback); 
    return map;
    }

}

The app is creating a pop-up with a graph. When the pop-up graph come up, it shows all 0. I printed out the values of the hashmap, the hashmap is getting populated with the correct data. Can’t figure out what I’m doing wrong here. Any help will be appreciated. Thanks

Following is my edited code….it works…thanks everyone!

public DialogBox getPopUpWarningGraph()
    {               
        SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
        AsyncCallback<LinkedHashMap<String, Integer>> callback = new AsyncCallback<LinkedHashMap<String, Integer>>()
        {
            @Override
            public void onFailure(Throwable caught) 
            {
            }

            @Override
            public void onSuccess(LinkedHashMap<String, Integer> result)
            {
                map = new LinkedHashMap<String,Integer>(result);

                Runnable onLoadCallback = new Runnable() 
                {
                    public void run() 
                    {
                        AbstractDataTable data = createLineTable(map);
                        Options options = createLineOptions();
                        LineChart lineChart = new LineChart(data, options);
                        vPanelWithGraph.add(lineChart);
                        vPanelWithGraph.add(closeGraphPopUp);
                    }
                };
                VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);             
            }
        };
        service.getDateAndWarningCount("",callback);
        popUpGraph.add(vPanelWithGraph);
        return popUpGraph;
    }

    private LineChart.Options createLineOptions() 
    {
        Options options = Options.create();
        options.setWidth(400);
        options.setHeight(240);
        options.setTitle("");
        return options;
    }

    private AbstractDataTable createLineTable(HashMap<String,Integer> map ) 
    {
        DataTable data = DataTable.create();
        data.addColumn(ColumnType.STRING, "Task");
        data.addColumn(ColumnType.NUMBER, "");

        data.addRows(map.size());

        Iterator it = map.entrySet().iterator();
        int i=0;
        while (it.hasNext()) 
        {
            Map.Entry pairs = (Map.Entry)it.next();
            data.setValue(i,0,pairs.getKey()+"");
            data.setValue(i,1,Integer.parseInt(pairs.getValue()+""));
            i++;
        }
        return data;
    }
}

so basically, getPopUpWarningGraph() function can be called from any class and it will return a popup with a graph!

  • 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-05-23T09:49:04+00:00Added an answer on May 23, 2026 at 9:49 am

    Your getDateAndWarningCount() returns immediately, before data is loaded – and it always returns null.

    In GWT (and javascript) you have to program asynchronously – execute your code when system calls you.

    In your case you have to execute drawing when onSuccess() is called, because this is when you have the data available.

    public void onModuleLoad()
    {
    
        Runnable onLoadCallback = new Runnable() 
        {
            public void run() {
                // first get the data
                getDateAndWarningCount()
            }          
        };
        VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE);
        popUpGraph.add(vPanelWithGraph);
    }
    
    private LineChart.Options createLineOptions() 
    {
        Options options = Options.create();
        options.setWidth(400);
        options.setHeight(240);
        options.setTitle("Graph Name");
        return options;
    }
    
    private AbstractDataTable createLineTable(HashMap<String,String> map) 
    {       
        DataTable data = DataTable.create();
        data.addColumn(ColumnType.STRING, "Date");
        data.addColumn(ColumnType.NUMBER, "Number");
    
        data.addRows(2);
    
        String [] arrDate = new String [2];
        int  [] arrWarCount = new int [2];
        int i=0;
        Iterator it = map.entrySet().iterator();
    
        while (it.hasNext()) 
        {
            Map.Entry pairs = (Map.Entry)it.next();
            System.out.println(pairs.getKey() + " = " + pairs.getValue());
            arrDate[i]=""+pairs.getKey();
            arrWarCount[i]=Integer.parseInt((String)pairs.getValue());
            i++;
        }
        data.setValue(0, 0, arrDate[0]);// row column
        data.setValue(0, 1, 5);
    
        data.setValue(1, 0, arrDate[1]);
        data.setValue(1, 1, 6);
    
        return data;
    }
    
    private HashMap<String,String> getDateAndWarningCount()
    {
        HashMap<String,String> map = null;
        SQLRunnerAsync service = (SQLRunnerAsync) GWT.create(SQLRunner.class);
        AsyncCallback<HashMap<String,String>>  callback = new AsyncCallback<HashMap<String,String>>()
        {
            @Override
            public void onFailure(Throwable caught) 
            {}
    
            @Override
            public void onSuccess(HashMap<String,String> result)
            {
                                Runnable onLoadCallback = new Runnable() 
                {
                    public void run() 
                    {
                        AbstractDataTable data = createLineTable(map);
                        Options options = createLineOptions();
                        LineChart lineChart = new LineChart(data, options);
                        vPanelWithGraph.add(lineChart);
                        vPanelWithGraph.add(closeGraphPopUp);
                    }
                };
                VisualizationUtils.loadVisualizationApi(onLoadCallback, LineChart.PACKAGE); 
            }
        };
        service.getHashMapValues(callback); 
        return map;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I have a text area in my form which accepts all possible characters from

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.