Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Cannot get simple chart example working(Chart example in the Technical Guide not working for me)
Cannot get simple chart example working [message #1856738] Tue, 27 December 2022 13:13 Go to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there everyone,

I'm having some trouble getting the most basic chart example to work in Eclipse Scout.

I am trying to implement the example in the technical guide: https://eclipsescout.github.io/22.0/technical-guide.html#how-to-create-a-chart

I decided to try in in the basic Hello Scout project.

The project's HelloWorldForm.java now looks like this:

@FormData(value = HelloWorldFormData.class, sdkCommand = FormData.SdkCommand.CREATE)
public class HelloWorldForm extends AbstractForm {

	public HelloWorldForm() {
		setHandler(new ViewHandler());
	}

	@Override
	protected boolean getConfiguredAskIfNeedSave() {
		return false;
	}

	@Override
	protected int getConfiguredModalityHint() {
		return MODALITY_HINT_MODELESS;
	}

	@Override
	protected String getConfiguredIconId() {
		return AbstractIcons.World;
	}

	public MainBox getMainBox() {
		return getFieldByClass(MainBox.class);
	}

	public ChartBox getChartBox() {
		return getFieldByClass(ChartBox.class);
	}

	public TopBox getTopBox() {
		return getFieldByClass(TopBox.class);
	}

	public MessageField getMessageField() {
		return getFieldByClass(MessageField.class);
	}

	@Order(1000)
	public class MainBox extends AbstractGroupBox {

		@Order(1000)
		public class TopBox extends AbstractGroupBox {

			@Override
			protected String getConfiguredLabel() {
				return TEXTS.get("MessageFromServer");
			}

			@Order(1000)
			public class MessageField extends AbstractStringField {
				@Override
				protected int getConfiguredGridW() {
					return 2;
				}

				@Override
				protected String getConfiguredLabel() {
					return TEXTS.get("Message");
				}

				@Override
				protected boolean getConfiguredEnabled() {
					return false;
				}
			}
		}

		@Order(2000)
		public class ChartBox extends AbstractGroupBox {
			@Override
			protected String getConfiguredLabel() {
				return TEXTS.get("Chart");
			}
		
			@Order(1000)
			public class ChartField extends AbstractChartField<Chart> {
				public class Chart extends AbstractChart {
					
					ChartData data = new ChartData();
					
					List<IChartAxisBean> axis = new ArrayList<>();
					Stream.of("Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.").forEach(label -> axis.add(new ChartAxisBean(label, label)));
					data.getAxes().add(axis);
					
					
					MonupleChartValueGroupBean vanilla = new MonupleChartValueGroupBean();
					vanilla.setGroupName("Vanilla");
					IntStream.of(0, 0, 0, 94, 162, 465, 759, 537, 312, 106, 0, 0)
					    .forEach(value -> vanilla.getValues().add(new BigDecimal(value)));
					data.getChartValueGroups().add(vanilla);

					MonupleChartValueGroupBean chocolate = new MonupleChartValueGroupBean();
					chocolate.setGroupName("Chocolate");
					IntStream.of(0, 0, 0, 81, 132, 243, 498, 615, 445, 217, 0, 0)
					    .forEach(value -> chocolate.getValues().add(new BigDecimal(value)));
					data.getChartValueGroups().add(chocolate);

					MonupleChartValueGroupBean strawberry = new MonupleChartValueGroupBean();
					strawberry.setGroupName("Strawberry");
					IntStream.of(0, 0, 0, 59, 182, 391, 415, 261, 75, 31, 0, 0)
					    .forEach(value -> strawberry.getValues().add(new BigDecimal(value)));
					data.getChartValueGroups().add(strawberry);

					chart.setData(data);				
				}
			}		
		
		}		
	}

	public class ViewHandler extends AbstractFormHandler {

		@Override
		protected void execLoad() {
			IHelloWorldService service = BEANS.get(IHelloWorldService.class);
			HelloWorldFormData formData = new HelloWorldFormData();
			exportFormData(formData);
			formData = service.load(formData);
			importFormData(formData);
		}
	}
}


The problem is that the project does not compile anymore because of 3 lines:
	List<IChartAxisBean> axis = new ArrayList<>();
	Stream.of("Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.").forEach(label -> axis.add(new ChartAxisBean(label, label)));
	data.getAxes().add(axis);


The errors I'm getting are in the attached screenshot

I know this may seem trivial but I really don't know where I got it wrong. Can anyone please help me figure this out. Thanks a lot.

Cheers,

JD
Re: Cannot get simple chart example working [message #1856739 is a reply to message #1856738] Tue, 27 December 2022 13:15 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Here is the scrrenshot. I forgot to put it in the message body.

Line 113 is the "Stream.of" line and line 114 is the "data.getAxes()" line.

Thanks

index.php/fa/42804/0/

[Updated on: Tue, 27 December 2022 13:22]

Report message to a moderator

Re: Cannot get simple chart example working [message #1856757 is a reply to message #1856739] Thu, 29 December 2022 08:51 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 230
Registered: September 2011
Senior Member
Hi J D

The issue here is, that you pasted the code snippet from the tutorial in the block

public class Chart extends AbstractChart {
}


This is not valid in Java. Instead you may paste it in a method e.g. in the "execLoad" method of the ViewHandler class. You are right, this is not explained very well in the tutorial. We need to improve this section in the future. Thank you for pointing that out.

To access the chart within "execLoad" you can use
getFieldByClass(TopBox.ChartBox.ChartField.class).getChart()
or create corresponding getters as e.g. for the MessageField (getMessageField).

Furthermore I would recommend to change the height of your ChartField e.g. using

@Override
protected int getConfiguredGridH() {
  return 6;
}


Hope this helps

Kind regards
Mat

[Updated on: Thu, 29 December 2022 08:55]

Report message to a moderator

Re: Cannot get simple chart example working [message #1856849 is a reply to message #1856738] Thu, 05 January 2023 14:02 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there Mat,

Thanks a lot for your reply and clarifications. I've moved the chart creation code into the ViewHandler's execLoad, but it still does not work.

This is what the HelloWorldForm.java class looks like now:

public class HelloWorldForm extends AbstractForm {

  public HelloWorldForm() {
    setHandler(new ViewHandler());
  }

  @Override
  protected boolean getConfiguredAskIfNeedSave() {
    return false;
  }

  @Override
  protected int getConfiguredModalityHint() {
    return MODALITY_HINT_MODELESS;
  }

  @Override
  protected String getConfiguredIconId() {
    return AbstractIcons.World;
  }

  public MainBox getMainBox() {
    return getFieldByClass(MainBox.class);
  }

  public ChartBox getChartBox() {
    return getFieldByClass(ChartBox.class);
  }
  
  public HelloScoutChartField getChartField() {
    return getFieldByClass(HelloScoutChartField.class);
  }

  public IChart getFieldChart() {
    return getChartField().getChart();
  }
  
  public TopBox getTopBox() {
    return getFieldByClass(TopBox.class);
  }

  public MessageField getMessageField() {
    return getFieldByClass(MessageField.class);
  }

  @Order(1000)
  public class MainBox extends AbstractGroupBox {

    @Order(1000)
    public class TopBox extends AbstractGroupBox {

      @Override
      protected String getConfiguredLabel() {
        return TEXTS.get("MessageFromServer");
      }

      @Order(1000)
      public class MessageField extends AbstractStringField {
        @Override
        protected int getConfiguredGridW() {
          return 2;
        }

        @Override
        protected String getConfiguredLabel() {
          return TEXTS.get("Message");
        }

        @Override
        protected boolean getConfiguredEnabled() {
          return false;
        }
      }
    }

    @Order(2000)
    public class ChartBox extends AbstractGroupBox {
      @Override
      protected String getConfiguredLabel() {
        return TEXTS.get("Chart");
      }
      
      @Order(1000)
      public class HelloScoutChartField extends AbstractChartField<IChart> {
        
        @Override
        protected int getConfiguredGridH() {
          return 10;
        }
        
        @Override
        protected boolean getConfiguredLabelVisible() {
          return false;
        };
        
        @Override
        protected boolean getConfiguredStatusVisible() {
          return false;
        };

        public class Chart extends AbstractChart {         
        }
      }
    }
       
  }

  public class ViewHandler extends AbstractFormHandler {

    @Override
    protected void execLoad() {
      IHelloWorldService service = BEANS.get(IHelloWorldService.class);
      HelloWorldFormData formData = new HelloWorldFormData();
      exportFormData(formData);
      formData = service.load(formData);
      importFormData(formData);
      
      // Chart creation
      ChartData data = new ChartData();

      List<IChartAxisBean> axis = new ArrayList<>();
      Stream.of("Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.")
          .forEach(label -> axis.add(new ChartAxisBean(label, label)));

      data.getAxes().add(axis);

      MonupleChartValueGroupBean vanilla = new MonupleChartValueGroupBean();
      vanilla.setGroupName("Vanilla");
      IntStream.of(0, 0, 0, 94, 162, 465, 759, 537, 312, 106, 0, 0)
          .forEach(value -> vanilla.getValues().add(new BigDecimal(value)));
      data.getChartValueGroups().add(vanilla);

      MonupleChartValueGroupBean chocolate = new MonupleChartValueGroupBean();
      chocolate.setGroupName("Chocolate");
      IntStream.of(0, 0, 0, 81, 132, 243, 498, 615, 445, 217, 0, 0)
          .forEach(value -> chocolate.getValues().add(new BigDecimal(value)));
      data.getChartValueGroups().add(chocolate);

      MonupleChartValueGroupBean strawberry = new MonupleChartValueGroupBean();
      strawberry.setGroupName("Strawberry");
      IntStream.of(0, 0, 0, 59, 182, 391, 415, 261, 75, 31, 0, 0)
          .forEach(value -> strawberry.getValues().add(new BigDecimal(value)));
      data.getChartValueGroups().add(strawberry);

      // Put the chart data in the chart field
      getChartBox().getFieldByClass(HelloScoutChartField.class).getChart().setData(data);
      
      //getChartField().getChart().setData(data);
    }
  }
}


This code throws an IllegalArgumentException shown below:

java.lang.IllegalArgumentException: No factory found for model null/HelloScoutChartField (org.eclipse.scout.apps.helloscout.client.helloworld.HelloWorldForm$MainBox$ChartBox$HelloScoutChartField)
	at org.eclipse.scout.rt.ui.html.json.MainJsonObjectFactory.createJsonAdapter(MainJsonObjectFactory.java:59)
	at org.eclipse.scout.rt.ui.html.UiSession.newJsonAdapter(UiSession.java:1093)
	at org.eclipse.scout.rt.ui.html.UiSession.createJsonAdapter(UiSession.java:1079)
	at org.eclipse.scout.rt.ui.html.UiSession.getOrCreateJsonAdapter(UiSession.java:1074)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.attachAdapter(AbstractJsonAdapter.java:207)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.createAdapter(JsonAdapterProperty.java:110)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.createAdapters(JsonAdapterProperty.java:94)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.createAdapters(JsonAdapterProperty.java:85)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.attachChildAdapters(JsonAdapterProperty.java:150)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonPropertyObserver.attachChildAdapters(AbstractJsonPropertyObserver.java:119)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonFormField.attachChildAdapters(JsonFormField.java:254)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.init(AbstractJsonAdapter.java:103)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonPropertyObserver.init(AbstractJsonPropertyObserver.java:53)
	at org.eclipse.scout.rt.ui.html.UiSession.newJsonAdapter(UiSession.java:1094)
	at org.eclipse.scout.rt.ui.html.UiSession.createJsonAdapter(UiSession.java:1079)
	at org.eclipse.scout.rt.ui.html.UiSession.getOrCreateJsonAdapter(UiSession.java:1074)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.attachAdapter(AbstractJsonAdapter.java:207)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.createAdapter(JsonAdapterProperty.java:110)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.createAdapters(JsonAdapterProperty.java:94)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.createAdapters(JsonAdapterProperty.java:85)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonAdapterProperty.attachChildAdapters(JsonAdapterProperty.java:150)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonPropertyObserver.attachChildAdapters(AbstractJsonPropertyObserver.java:119)
	at org.eclipse.scout.rt.ui.html.json.form.fields.JsonFormField.attachChildAdapters(JsonFormField.java:254)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.init(AbstractJsonAdapter.java:103)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonPropertyObserver.init(AbstractJsonPropertyObserver.java:53)
	at org.eclipse.scout.rt.ui.html.UiSession.newJsonAdapter(UiSession.java:1094)
	at org.eclipse.scout.rt.ui.html.UiSession.createJsonAdapter(UiSession.java:1079)
	at org.eclipse.scout.rt.ui.html.UiSession.getOrCreateJsonAdapter(UiSession.java:1074)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.attachAdapter(AbstractJsonAdapter.java:207)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.attachAdapter(AbstractJsonAdapter.java:196)
	at org.eclipse.scout.rt.ui.html.json.form.JsonForm.attachChildAdapters(JsonForm.java:156)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.init(AbstractJsonAdapter.java:103)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonPropertyObserver.init(AbstractJsonPropertyObserver.java:53)
	at org.eclipse.scout.rt.ui.html.json.form.JsonForm.init(JsonForm.java:72)
	at org.eclipse.scout.rt.ui.html.UiSession.newJsonAdapter(UiSession.java:1094)
	at org.eclipse.scout.rt.ui.html.UiSession.createJsonAdapter(UiSession.java:1079)
	at org.eclipse.scout.rt.ui.html.UiSession.getOrCreateJsonAdapter(UiSession.java:1074)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.attachGlobalAdapter(AbstractJsonAdapter.java:312)
	at org.eclipse.scout.rt.ui.html.json.AbstractJsonAdapter.attachGlobalAdapter(AbstractJsonAdapter.java:302)
	at org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline.attachNode(JsonOutline.java:132)
	at org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline.handleModelPageChanged(JsonOutline.java:281)
	at org.eclipse.scout.rt.ui.html.json.desktop.JsonOutline.handleModelOtherTreeEvent(JsonOutline.java:266)
	at org.eclipse.scout.rt.ui.html.json.tree.JsonTree.processBufferedEvent(JsonTree.java:578)
	at org.eclipse.scout.rt.ui.html.json.tree.JsonTree.processBufferedEvents(JsonTree.java:521)
	at org.eclipse.scout.rt.ui.html.json.JsonResponse.fireProcessBufferedEvents(JsonResponse.java:354)
	at org.eclipse.scout.rt.ui.html.json.JsonResponse.toJson(JsonResponse.java:287)
	at org.eclipse.scout.rt.ui.html.UiSession.responseToJsonInternal(UiSession.java:834)
	at org.eclipse.scout.rt.ui.html.UiSession.lambda$6(UiSession.java:852)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:227)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:227)
	at org.eclipse.scout.rt.platform.transaction.TransactionProcessor.runTxMandatory(TransactionProcessor.java:156)
	at org.eclipse.scout.rt.platform.transaction.TransactionProcessor.runTxRequired(TransactionProcessor.java:139)
	at org.eclipse.scout.rt.platform.transaction.TransactionProcessor.intercept(TransactionProcessor.java:78)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:222)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain.call(CallableChain.java:170)
	at org.eclipse.scout.rt.platform.context.RunContext.call(RunContext.java:158)
	at org.eclipse.scout.rt.platform.context.RunContextRunner.intercept(RunContextRunner.java:38)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:222)
	at org.eclipse.scout.rt.platform.job.internal.CallableChainExceptionHandler.intercept(CallableChainExceptionHandler.java:33)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain$Chain.continueChain(CallableChain.java:222)
	at org.eclipse.scout.rt.platform.chain.callable.CallableChain.call(CallableChain.java:170)
	at org.eclipse.scout.rt.platform.job.internal.JobFutureTask.lambda$0(JobFutureTask.java:106)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at org.eclipse.scout.rt.platform.job.internal.JobFutureTask.run(JobFutureTask.java:175)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:829)
	at org.eclipse.scout.rt.platform.job.internal.NamedThreadFactory$1.run(NamedThreadFactory.java:63)



How do I get around this problem?

Thanks,

JD
Re: Cannot get simple chart example working [message #1856855 is a reply to message #1856849] Thu, 05 January 2023 16:35 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
The exception occurs here:

      // Put the chart data in the chart field
      getChartBox().getFieldByClass(HelloScoutChartField.class).getChart().setData(data);
      
      //getChartField().getChart().setData(data);
Re: Cannot get simple chart example working [message #1856856 is a reply to message #1856855] Thu, 05 January 2023 17:10 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 230
Registered: September 2011
Senior Member
Hi J D

Did you add the pom.xml and package.json dependencies for the chart modules as described in the chapter "Prerequisites" in the chart how-to?

If yes, you might need to download/update these dependencies. In eclipse you can do that using Alt+F5.

Does this help?

Kind regards
Mat

[Updated on: Thu, 05 January 2023 17:11]

Report message to a moderator

Re: Cannot get simple chart example working [message #1856872 is a reply to message #1856856] Fri, 06 January 2023 12:00 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there Mat,

Yes, I've updated Maven project several times. I decided to start all over on another Linux box with a fresh Eclipse installation and download of the HelloScout demo BUT the result is the same: java.lang.IllegalArgumentException

The problem with the tutorial is the line
chart.setData(data);
. I realize that this is what I'm trying to replace with
getChartBox().getFieldByClass(HelloScoutChartField.class).getChart().setData(data)

No reference to it exists. Should it refer to the inner class

public class Chart extends AbstractChart {         
}

In addition, should that inner class be empty?

Thanks,

JD

[Updated on: Fri, 06 January 2023 12:01]

Report message to a moderator

Re: Cannot get simple chart example working [message #1856875 is a reply to message #1856872] Fri, 06 January 2023 14:25 Go to previous messageGo to next message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 230
Registered: September 2011
Senior Member
Hi J D

I just created a new helloworld application and replaced the HelloWorldForm with your code.
After that I changed the following:
1. I added the dependencies to the pom.xml as explained in the howto (1 in client module, 1 in shared module and 1 in ui.html module)
2. I updated all maven dependencies in the IDE.
3. I had to add some imports to your HelloWorldForm so that all inner classes can be found.
4. I Added the chart dependency to the package.json as explained in the howto.
5. I Added the import to the index.js as explained in the howto.
6. I added the imports to the helloscout-theme.less and helloscout-theme-dark.less as explained in the howto.

Then the charts works for me. So the issue might not be related to the code in the HelloWorldForm or your imports may be wrong.

If this does not help, maybe you can provide your helloworld sample and I could have a look at it.

Kind regards
mat
Re: Cannot get simple chart example working [message #1856877 is a reply to message #1856875] Fri, 06 January 2023 15:24 Go to previous messageGo to next message
J D is currently offline J DFriend
Messages: 95
Registered: February 2021
Member
Hi there Mat,

Thanks a million. IT WORKS!!!!!

The problem is the way the Technical Guide was written:

index.php/fa/42821/0/

Because of the use of the word OR instead of AND above, I was under the impression that I only needed to add one chart dependency to get it working. So I added it to the pom.xml of the client and ignored the others.

Thank you so much for taking the time to clarify this issue for me.

Cheers,

JD

[Updated on: Fri, 06 January 2023 15:25]

Report message to a moderator

Re: Cannot get simple chart example working [message #1856878 is a reply to message #1856877] Fri, 06 January 2023 15:42 Go to previous message
Matthias Villiger is currently offline Matthias VilligerFriend
Messages: 230
Registered: September 2011
Senior Member
Hi J D

Glad it works now. And you are right, the howto could be more clear. We will improve that in the future. Thanks for pointing that out!

Cheers
Mat
Previous Topic:Cannot build without clean
Next Topic:Hiding in status of TablePage when including in form Using PageField
Goto Forum:
  


Current Time: Mon Mar 04 13:00:02 GMT 2024

Powered by FUDForum. Page generated in 0.01890 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top