In your case the only thing that is wrong is that you are calling the getValues after getting the range (Line 2). To fix it just remove the getValues(). See the code fixed bellow:
var ss = SpreadsheetApp.openById("myid");
var datatable = ss.getSheetByName("Chart sheet").getRange("A1:H4");
var chart = Charts.newColumnChart()
.setDataTable(dataTable)
.setRange(0, 40)
.setTitle('Chart')
.setLegendPosition(Charts.Position.BOTTOM)
.setDimensions(600, 300)
.build();
The API can be found here.