I see 2 tasks here. In general you first prepare 2 API endpoints to deliver the data to your frontend (keep in mind, JHI provides both server and client), and then using plotly (js) to do your plots
preparing API
you should translate your SQL query to JPA, like this:
public interface BookRepository extends JpaRepository<Book,Long> {
@Query("select b.authorId, count(b.id) from Book b group by b.authorId ")
List<Book> findAllGroupByAuthor();
@Query("select b.authorId, YEAR(b.publicationDate) as year,count(*) from Book b group by b.authorId, b.year")
List<Book> findAllGroupByAuthorAndYear();
}
then you add this to some RestControllers. Here is an example
@RestController
@RequestMapping("/api/books/query/")
public class CustomBookQueryResource {
private BookRepository bookRepository;
public CustomBookQueryResource(BookRepository bookRepository) {
this.bookRepository = bookRepository;
}
@GetMapping("/group_by_author")
public ResponseEntity<List<Book>> groupByAuthor() {
return ResponseEntity.ok(bookRepository.findAllGroupByAuthor());
}
@GetMapping("/group_by_author_and_year")
public ResponseEntity<List<Book>> groupByAuthorAndYear() {
return ResponseEntity.ok(bookRepository.findAllGroupByAuthorAndYear());
}
}
so until this point, you should already have some api endpoints, serving your data. Now you should add your custom query book service in angular
angular
.module('<yourApp>')
.factory('CustomBookQuery', CustomBookQuery);
CustomBookQuery.$inject = ['$http'];
function CustomBookQuery ($http) {
var resourceUrl = 'api/books/query/';
return {
findAllGroupByAuthor: function () {
return $http.get(resourceUrl + 'group_by_author');
},
findAllGroupByAuthorAndYear: function () {
return $http.get(resourceUrl + 'group_by_author_and_year');
}
};
}
Now you just can inject your service and pass its promises resolves to your plotly, which is already has and JS part and a Angular implementation
(I coded above code from mind, so it's not tested)