org.dashbuilder.renderer.chartjs.lib.PieChart Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dashbuilder-renderer-chartjs Show documentation
Show all versions of dashbuilder-renderer-chartjs Show documentation
Dashbuilder Renderer for the Chart JS API
package org.dashbuilder.renderer.chartjs.lib;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.dom.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.dashbuilder.renderer.chartjs.lib.data.PieChartDataProvider;
import org.dashbuilder.renderer.chartjs.lib.data.Series;
public class PieChart extends ChartWithScale {
private PieChartDataProvider provider;
@Override
public void draw() {
reload();
}
private native void drawPie(JavaScriptObject data)/*-{
canvas = [email protected]::getNativeElement()();
nativeCanvas = [email protected]::getNativeCanvas()();
if(nativeCanvas != null) {
nativeCanvas.destroy();
}
options = [email protected]::constructOptions()();
nativeCanvas = new $wnd.Chart(canvas.getContext("2d")).Pie(data,options);
[email protected]::setNativeCanvas(Lcom/google/gwt/core/client/JavaScriptObject;)(nativeCanvas);
}-*/;
@Override
public void update() {
if(provider == null)
throw new NullPointerException("PieChartDataProvider not initialized before invoking update()");
drawPie(provider.getData());
}
@Override
public void reload() {
if(provider == null)
throw new NullPointerException("PieChartDataProvider not initialized before invoking update()");
//TODO: show loading
provider.reload(new AsyncCallback>() {
@Override
public void onSuccess(JsArray result) {
drawPie(provider.getData());
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
public void setDataProvider(PieChartDataProvider provider){
this.provider = provider;
}
}