How to instanciate from the BasicDataset Class?

Hello all,

In my SDK exploration, I have to create a component that would have a Dataset type property (like, for exemple, a table or a chart).

The problem I have is to use the contructor, especially for the columnTypes parameter. The javadoc reads that the type of this parameter is : java.util.List<java.lang.Class<?>> which is not really clear for me.

I created a List and tried to add things like “String.class” or “Integer.class” but that makes the system unhappy as an “UnsupportedOperationException” is thrown.

Has someone would be willing to share an exemple of creating/using a Dataset ?

Thank you.

You’re on the right track. I’m not sure why you can’t make a list of classes, though. Some examples (imports omitted for brevity):[code]List myHeaders = new ArrayList();
List<Class<?>> myTypes = new ArrayList>();
Dataset empty = new BasicDataset(myHeaders, myTypes);

String[] column1Data = new String[] {“Row 1 Text”, “Row 2 Text”, “3rd Row Text”};
Integer[] column2Data = new Integer[] {25, 30, 155};
Dataset threeRows = new BasicDataset(myHeaders, myTypes,
new Object[][] { column1Data, column2Data});
[/code]As you can see above, the constructor for a BasicDataset constructs a fully-populated, non-editable dataset in one go. This isn’t always convenient, so Ignition provides com.inductiveautomation.ignition.common.util.DatasetBuilder to simplify the process:DatasetBuilder builder = DatasetBuilder.newBuilder(); builder.colNames("FirstColumn", "SecondColumn"); builder.colTypes(String.class, Integer.class); builder.addRow("First Row Text", 55); builder.addRow("Second Row Text", -234); builder.addRow("Third Row Text", 8080); builder.addRow("Fourth Row Text", -91); Dataset fourRows =;If you look close at the builder methods’ JavaDocs, you’ll see that all but the last return the builder object, allowing you to string the method calls together on one logical line. Pretty handy.

Thanks a lot for your reply.

I was using Arrays.asList(), I think that the error came from here.

Let the exploration continue.