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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:22:43+00:00 2026-05-27T08:22:43+00:00

I’m trying to get the method data.SetValue(…) working in the asynchronous callback in method

  • 0

I’m trying to get the method data.SetValue(...) working in the asynchronous callback in method getNames. Unfortunately it doesn’t work. data.setValue(...) does work in the synchronous method createColumnChartView.

What could be the cause of this problem? Please explain why setting data doesn’t work in getNames. Thanks in advance!

import java.util.ArrayList;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Widget; 
import com.google.gwt.visualization.client.DataTable;
import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
import com.google.gwt.visualization.client.visualizations.corechart.ColumnChart;
import com.google.gwt.visualization.client.visualizations.corechart.CoreChart;
import com.google.gwt.visualization.client.visualizations.corechart.Options;
import com.practicum.client.Product;
import com.practicum.client.rpc.ProductService;
import com.practicum.client.rpc.ProductServiceAsync;


public class DataOutColumnChart {
private final DataTable data = DataTable.create();
private final Options options = CoreChart.createOptions();
private final ProductServiceAsync productService = GWT.create(ProductService.class);

public DataOutColumnChart(Runnable runnable) {
}

public Widget createColumnChartView() {
    /* create a datatable */
    data.addColumn(ColumnType.STRING, "Price");
    data.addColumn(ColumnType.NUMBER, "EUR");
    data.addRows(2);
    data.setValue(0, 0, "Bar 1");
    data.setValue(0, 1, 123);
    getNames();

    /* create column chart */
    options.setWidth(400);
    options.setHeight(300);
    options.setBackgroundColor("#e8e8e9");

    return new ColumnChart(data, options);
}

public void getNames() {
    productService.getNames(new AsyncCallback<ArrayList<Product>>() {
        public void onFailure(Throwable caught) {
        }

        public void onSuccess(ArrayList<Product> result) {
            for (Product p : result) {
                data.setValue(0, 0, "Bar 2"); // DONT WORK, NOTHING HAPPENS
                data.setValue(0, 1, 345); // DONT WORK, NOTHING HAPPENS
                System.out.println("Bla bla test"); // THIS WORKS
            }
        }
    });
}
}
  • 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-27T08:22:44+00:00Added an answer on May 27, 2026 at 8:22 am

    The problem is occurring because you’re setting data to a DataTable that has already been rendered. Your Asynchronous call in getNames() completes too slowly to affect the DataTable in time for the rendering of the ColumnChart. Even if it did complete fast enough, it would always be a race condition. Ideally, you would not actually render that chart until after you’ve received all necessary data from the RPC call.

    Another option is to store a reference to that ColumnChart and call columnChart.draw(...) after you get your data back from RPC.

    Edit:

    Here’s the example you requested.

    import java.util.ArrayList;
    import com.google.gwt.core.client.GWT;
    import com.google.gwt.user.client.rpc.AsyncCallback;
    import com.google.gwt.user.client.ui.Widget; 
    import com.google.gwt.visualization.client.DataTable;
    import com.google.gwt.visualization.client.AbstractDataTable.ColumnType;
    import com.google.gwt.visualization.client.visualizations.corechart.ColumnChart;
    import com.google.gwt.visualization.client.visualizations.corechart.CoreChart;
    import com.google.gwt.visualization.client.visualizations.corechart.Options;
    import com.practicum.client.Product;
    import com.practicum.client.rpc.ProductService;
    import com.practicum.client.rpc.ProductServiceAsync;
    
    
    public class DataOutColumnChart {
        private final DataTable data = DataTable.create();
        private final Options options = CoreChart.createOptions();
        private final ProductServiceAsync productService = GWT.create(ProductService.class);
        private ColumnChart chart = null;
    
        public DataOutColumnChart(Runnable runnable) {
        }
    
        public void initColumnChart() {
            /* create a datatable */
            data.addColumn(ColumnType.STRING, "Price");
            data.addColumn(ColumnType.NUMBER, "EUR");
    
            /* create column chart */
            options.setWidth(400);
            options.setHeight(300);
            options.setBackgroundColor("#e8e8e9");
    
            chart = new ColumnChart(data, options);
        }
    
        public void getNames() {
            productService.getNames(new AsyncCallback<ArrayList<Product>>() {
                public void onFailure(Throwable caught) {
                }
    
                public void onSuccess(ArrayList<Product> result) {
                    if (result != null && result.size() > 0) {
                        // if there is data...
                        data.addRows(result.size()); // add a row for each result
                        for (int i = 0; i < result.size(); i++) {
                            // loop through the results
                            Product product = result.get(i); // get out the product
                            // ...then set the column values for this row
                            data.setValue(i, 0, product.getSomeProperty());
                            data.setValue(i, 1, product.getSomeOtherProperty());
                        }
                        updateChart();
                    }
                }
            });
        }
    
        public void updateChart() {
            chart.draw(data, options);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.