Here's a similar approach that uses the Tabulate platform.
dt = New Table( "Untitled", Add Rows( 10 ),
New Column( "Year", Numeric, "Ordinal", Format( "Best", 12 ),
Set Values( [2015, 2015, 2016, 2016, 2016, 2016, 2016, 2017, 2017, 2017] ) ),
New Column( "Batch", Character( 16 ), "Nominal",
Set Values( {"A", "A", "B", "C", "C", "C", "C", "D", "E", "E"} ) ),
New Column( "Sample", Character( 16 ), "Nominal",
Set Values( {"A1", "A2", "B1", "C1", "C2", "C3", "C4", "D1", "E1", "E2"} ) ),
New Column( "Value", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [2, 5, 3, 8, 1, 2, 10, 0, 5, 6] ) )
);
dt_tab = (dt << Tabulate(
Show Control Panel( 0 ),
Add Table( Row Table( Grouping Columns( :Year, :Batch ) ) )
)) << Make Into Data Table;
dt_tab << Graph Builder(
Show Control Panel( 0 ),
Variables( X( :Year ), Y( :N ), Overlay( :Batch ) ),
Elements( Bar( X, Y, Legend( 9 ), Bar Style( "Stacked" ) ) )
);