pepstock-org / Charba

J2CL and GWT Charts library based on CHART.JS
https://pepstock-org.github.io/Charba-Wiki/docs
Apache License 2.0
62 stars 6 forks source link

Problem with displaying MeterChart after upgrading to version 2.8 #52

Closed ssamikk closed 4 years ago

ssamikk commented 4 years ago

With version 2.6, everything works. After the update, I get the following error:

ChartNode.java:212 Uncaught TypeError: Cannot read property 'innerRadius' of undefined at Utv_g$.cuv_g$ [as getInnerRadius_0_g$] (ChartNode.java:212) at a$w_g$.d$w_g$ [as execute_5_g$] (BaseMeterController.java:166) at a$w_g$.c$w_g$ [as draw_4_g$] (BaseMeterController.java:139) at Fiw_g$.Siw_g$ [as onDraw_0_g$] (WrapperController.java:339) at Fiw_g$.Miw_g$ [as lambda$3_14_g$] (WrapperController.java:252) at Function.zjw_g$ (WrapperController.java:252) at n.lambda_0_g$ (Runtime.java:166)

My code:

MeterChart chart = new MeterChart(); chart.getOptions().getTitle().setDisplay(false); chart.getOptions().setDisplay(MeterDisplay.VALUE); chart.getOptions().setFormat("###.## "+check.getUnits()); chart.getOptions().setResponsive(true);

    MeterDataset dataSet = chart.newDataset(check.getMaxValue());
    dataSet.setValue(check.getLastVarValue());
    chart.getData().setDatasets(dataSet);`

Tell me what I'm doing wrong.

stockiNail commented 4 years ago

@ssamikk I've tested your code with 2.8 in my tester app, as following:;

public void onModuleLoad() {

   ResourcesType.setClientBundle(EmbeddedResources.INSTANCE);

   MeterChart chart = new MeterChart();
   chart.getOptions().getTitle().setDisplay(false);
   chart.getOptions().setDisplay(MeterDisplay.VALUE);
   chart.getOptions().setFormat("###.## units");
   chart.getOptions().setResponsive(true);

   MeterDataset dataSet = chart.newDataset(90);
   dataSet.setValue(10);
   chart.getData().setDatasets(dataSet);

   RootPanel.get().add(chart);
}

This is the result:

bug52

Do you have anything else to try to reproduce the error ?

ssamikk commented 4 years ago

Thanks for the quick response. I will deal with what I am doing wrong.

stockiNail commented 4 years ago

@ssamikk let me know if you are able to solve it. I'm doing some tests and I'm not able to have that exception.

That exception means Chart object (native instance of Chart.js) doesn't have the "innerRadius" property (read it by jstype native). It sounds a little bit strange.

ssamikk commented 4 years ago

hellogwt.zip I tried on the simplest project. Got the same result

stockiNail commented 4 years ago

@ssamikk I think I found the reason of the issue because I got the same.

Are you sure you have added -generateJsInteropExports to GWT compiler?

From Doc:

Pay attention that GWT compiler (you are using for your project) requires -generateJsInteropExports to be passed.

This is mandatory from version 2.x and be aware that the compiler will end correctly and you have this error at runtime.

ssamikk commented 4 years ago

I apologize for my carelessness. Really missing one line in the gwt-maven-plugin configuration <generateJsInteropExports> true </generateJsInteropExports> Many thanks for the help

stockiNail commented 4 years ago

@ssamikk no problem at all. This is a common issue and GWT compiler does not help because it does not provide any warning when that parameter for JSINTEROP is missing.

Furthermore this issue has helped to improve a statement into BaseMeterController.

It has also enforced our idea to improve the controller part in the next major version, for instance improving the enable of javascript controllers injection (see some additional chart types developed by others) or to use defaults (global and chart type) for meter and gauge types that at the moment can be configured ONLY at char level.

I'm gonna add the Maven configuration that you shared into Wiki, as reminder, for who will use Maven.

Thank you very much!