org.dashbuilder.renderer.chartjs.lib.RadarChart 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.dom.client.Element;
import com.google.gwt.user.client.rpc.AsyncCallback;
import org.dashbuilder.renderer.chartjs.lib.data.AreaChartData;
import org.dashbuilder.renderer.chartjs.lib.data.AreaChartDataProvider;
public class RadarChart extends ChartWithScale {
private AreaChartDataProvider provider;
private boolean scaleShowLabels = false;
@Override
public void draw() {
reload();
}
public void setScaleShowLabels(boolean scaleShowLabels){
this.scaleShowLabels = scaleShowLabels;
}
private native void drawRadar(JavaScriptObject data)/*-{
canvas = [email protected]::getNativeElement()();
nativeCanvas = [email protected]::getNativeCanvas()();
if(nativeCanvas != null) {
nativeCanvas.destroy();
}
var options = [email protected]::constructOptions()();
if(options == null)
options = {scaleShowLabels : true, pointLabelFontSize : 10};
nativeCanvas = new $wnd.Chart(canvas.getContext("2d")).Radar(data,options);
[email protected]::setNativeCanvas(Lcom/google/gwt/core/client/JavaScriptObject;)(nativeCanvas);
}-*/;
@Override
public void update() {
if(provider == null)
throw new NullPointerException("PieCharDataProvider was not initialized before invoking update()");
drawRadar(provider.getData());
}
@Override
public void reload() {
if(provider == null)
throw new NullPointerException("PieCharDataProvider was not initialized before invoking reload()");
//TODO: show loading..
provider.reload(new AsyncCallback() {
@Override
public void onSuccess(AreaChartData result) {
drawRadar(result);
}
@Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
public void setDataProvider(AreaChartDataProvider provider){
this.provider = provider;
}
}