Class DonutChart

All Implemented Interfaces:
DataDescriptorCallback, ClickableChartData<DonutChart>, SimpleSeriesChart<DonutChart,Series>

A donut chart is a circle diagram with an empty area in the middle. The chart displays data series As a circle with data points visualized as the slices of a circle. The length of each slice is determined by calculating their proportion to the entire circle. The color of circle slices is automatically calculated, but you can also specify them. Each circle slice is displayed separately on the legend, providing information to the user about the chart’s data categories. Slices are automatically displayed in percentage (meaning what percentage of the entire circle they represent). You can also modify if the actual data values, a percentage or no labels should be displayed on the slice. Slice thickness is automatically calculated, but you can also modify it.

This chart is does not allow you to modify the tooltip, you can only use a DOT. However, the chart enables you to create custom tooltips using any JBStrap component. If you want to display a tooltip that is different from the default one, you need to create it on your own using ChartTooltipRenderer. You only need to implement one method which returns the tooltip as a component. In order to do this, you can reuse any JBStrap component. It is possible to display a button, a list or even another chart on the tooltip.

The chart also supports click events. This means that you can implement server-side business logic for the event that is triggered when a user clicks on a data point. This is when a ChartClick event is triggered. This event provides you information on where and which chart the user clicked on. This can be reused in various ways, e.g. to update a list.

Since:
4.0
Author:
JBStrap
See Also:
  • Field Details

  • Constructor Details

    • DonutChart

      public DonutChart(String name)
      Creates a donut chart.
      Parameters:
      name - Chart name (required)
      Throws:
      NullPointerException - Thrown if the specified chart name is null
    • DonutChart

      public DonutChart(String name, DataDescriptor dataDescriptor, String categoryColumnName)
      Creates a donut chart and sets the name of the associated DataDescriptor and category column.
      Parameters:
      name - Chart name (required)
      dataDescriptor - The DataDescriptor instance from where the component retrieves its value set
      categoryColumnName - Category data column name
      Throws:
      NullPointerException - Thrown if the specified chart name is null
  • Method Details

    • init

      protected void init()
      Description copied from class: BaseChart
      Chart initialization.
      Specified by:
      init in class BaseChart<DonutChart>
    • setDataLabels

      public DonutChart setDataLabels(DataLabels labels)
      Sets the label for each circle slice. By default, the label shows how much per cent a data point represents of the entire circle.
      Parameters:
      labels - Label type Available types are listed in the enum DataLabels. If null is specified, the label is not displayed on the circle slice.
      Returns:
      Chart instance
    • getDataLabels

      public DataLabels getDataLabels()
      Gets the type of the labels from a circle slice.
      Returns:
      Label type
    • setPaddingAngle

      public DonutChart setPaddingAngle(Integer padding)
      Sets the size of the empty area (padding) between two circle slices. The default padding size is 1.
      Parameters:
      padding - Padding size between circle slices
      Returns:
      Chart instance
    • getPaddingAngle

      public Integer getPaddingAngle()
      Gets the size of the empty area (padding) between two circle slices.
      Returns:
      Padding size between circle slices
    • setThickness

      public DonutChart setThickness(Integer thickness)
      Adjusts the radius of the inner circle. By default, the radius of the inner circle is 38% of the radius of the outer circle.
      Parameters:
      thickness - The inner circle radius percentage
      Returns:
      Chart instance
    • getThickness

      public Integer getThickness()
      Gets the inner circle radius.
      Returns:
      The inner circle radius percentage
    • setBorderColor

      public DonutChart setBorderColor(String color)
      Sets the border color for the circle slices. By default, circle slices are enclosed by a white border.
      Parameters:
      color - Border color in CSS3 format
      Returns:
      Chart instance
    • getBorderColor

      public String getBorderColor()
      Gets the border color for the circle slices.
      Returns:
      Border color in CSS3 format
    • setBorderWidth

      public DonutChart setBorderWidth(int width)
      Sets the border width. By default, circle slices are enclosed by a 0 pixels thick border (no visible border).
      Parameters:
      width - Border width in pixels If a number smaller than 0 is specified, border width is set to 0. No visible border is displayed.
      Returns:
      Chart instance
    • getBorderWidth

      public int getBorderWidth()
      Gets the width of the border around circle slices.
      Returns:
      Border width around circle slices
    • setBorderRadius

      public DonutChart setBorderRadius(int radius)
      Sets the rounding radius of circle slice corners. By default, circle slices are not rounded (the rounding radius is 0).
      Parameters:
      radius - Rounding radius of circle slices in pixels If a number smaller than 0 is specified, the rounding radius is set to 0. Circle slices are not rounded.
      Returns:
      Chart instance
    • getBorderRadius

      public int getBorderRadius()
      Gets the rounding radius of circle slice corners.
      Returns:
      Rounding radius of circle slices in pixels
    • setSeries

      public DonutChart setSeries(Series series)
      Sets the series displayed on the chart.
      Specified by:
      setSeries in interface SimpleSeriesChart<DonutChart,Series>
      Parameters:
      series - Series instance displayed on the chart
      Returns:
      Chart