Jump to content
  • Creating Charts and Datasets with Jaspersoft Studio


    morlandin
    • Edited on:
    • Features: Charts Version: v8.0.0 Product: Jaspersoft® Studio

    Overview

    You should complete the tutorial "Creating Charts and Subreports with Jaspersoft Studio" before beginning this tutorial, as it introduces the Datasets and uses them in the creation of a chart. The goal of this tutorial is to create a report with a chart in its summary, with some grouped data. Although this can be done by using a subreport, in this tutorial we will use only one report and a "dataset" element.

    Preliminary Steps

    In this tutorial, we will use the report created during the tutorial "Designing a Report with Jaspersoft Studio" which provides us a report including all the records in the table "orders", with every record including the field order id, shipment name, shipment address, shipment city, and shipment region. At the bottom of the records, in the Summary band, we want to include a chart that shows the number of shipments for every city. If you haven't followed the tutorial "Creating Charts and Subreports with Jaspersoft Studio" you need to resize the Summary band with the following procedure. The Summary band is already present in the report used as example, but it could have an height of 0. It is, however, visible from the outline view. Select the Summary band from the Outline view and change its height in the property tab to 400 pixels, as shown in the following image:

    1(11).png.eac9ef4d961e5a198ca4368e44d9bf74.png

    The Dataset

    Every report has a main dataset defined during its creation. But sometimes we need fields that are not returned by a query from the main dataset, or the fields needed may be in a different data source. In the tutorial "Creating Charts and Subreports with Jaspersoft Studio" we saw a workaround where we define more reports using only the main dataset of each report, and including them in another report using the element "Subreport". Another way to do this is using a single report and the element "Dataset". The dataset element allows you to define many datasets inside the report, each one with its own fields and data source. Every dataset is independent from the others, so its fields are separated from the ones of the main dataset, and also from the ones of the other datasets

    To create a dataset, right-click on the report root node in the outline view and choose Create Dataset:

    1(12).png.8ce497e43daeaca9f95cf4e5278f43e5.png

    A new wizard opens. In the first step, enter a name for the new dataset and if it uses a connection to a data source or it is simply empty. Since we want to read data from the database, select the first option and use as name "GroupData", as in the image below, then click Next.

    2(9).png.a64ff0deace14e6ab87d72c4790ee29d.png

    Next, we have to select the data adapters for the new dataset, and since we are using the same database as the main report , we will select Sample DB - Database JBDC Connection. We must also provide a query to retrieve the fields. Enter the query "select count(*), SHIPCITY from orders group by SHIPCITY". It returns the records grouped by the shipment city. This ensures that every record read from the database that matches this query will contain two fields: the number of element for a city and the name of the city. After that we can click Next.

    3(5).png.471ea32eccfae7423bd44380a2718062.png

    At this point, the fields discovered using the provided query are displayed, and we can choose which we want to add to the report. Since we need them all click the Add All button and then Next, as in the following image:

    4(5).png.6b5b020db7c80072fe2c17fb541c61a0.png

    On the next screen in the wizard, we can define groups. For this task, we don't need them so click the Finish button. The dataset is created and is visible from the Outline view. If you explore the element you can see that it has its own fields, variables and groups. We can now drag and drop the chart from the palette into the Summary section:

    5(4).png.d752053634c55a31d9d96c61452064f7.png

    After the chart is placed the, creation wizard appears. On the first screen, select a Pie Chart (to have something different from the previous tutorial), and click Next. On the next screen, find the field named Dataset, normally with the value [MainDataset]. You must change this value to GroupData, so the chart will use the new dataset, as in the image below:

    6(4).png.3755bc3c95aedee599aeb5b80d2a9844.png

    Now you have to configure the series of the chart. Click the button with three dots on the right of the series combo to open a new dialog:

    7(2).png.fd999ba69642e1981229c9b711dfefe0.png

    In this dialog you can define the series of the chart with an expression. Delete the default item by selecting it and clicking Delete, then press the Add button. The expression editor opens. Select, Fields and double-click on the item SHIPCITY. Finally, click "Finish" to close the expression editor:

    8(2).png.7538195a12a9884459ab32ae47d7b3b0.png

    Now you will return to the dialog of the series. Click Ok to go to the chart configuration. Configure it as shown in the following image:

    9(2).png.edab5905ec32cc22d2d200c7b5d2aacd.png

    When the chart configuration is finished, click the Finish to complete the wizard. The only thing left to do is resize the chart to take up all available space in its band. Right-click on the chart, select Size to Container, and then Fit Both. The chart fills the Summary band. Next, go in the Preview tab to compile the report, then go to the last page to see the chart:

    10(2).png.c8c5b7232094a33194a869f0e545e307.png


    User Feedback

    Recommended Comments

    rutuja.gogte

    Posted

    Can we do the similar thing with json datasource where i would be showing slices on some grouped key and its value would be count of objects in that group



    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

×
×
  • Create New...