From 38a31d5c3f3b84418acd73e2be0f4229a77d1e28 Mon Sep 17 00:00:00 2001 From: Bartosz Schiller Date: Tue, 25 Jun 2024 02:56:16 +0200 Subject: [PATCH] Add support for simple horizontal bar chart --- README.md | 34 ++- .../horizontalbar/HorizontalBarChart01.java | 61 +++++ .../horizontalbar/HorizontalBarChart02.java | 85 ++++++ .../horizontalbar/HorizontalBarChart03.java | 78 ++++++ .../horizontalbar/HorizontalBarChart04.java | 66 +++++ .../org/knowm/xchart/HorizontalBarChart.java | 247 +++++++++++++++++ .../xchart/HorizontalBarChartBuilder.java | 35 +++ .../org/knowm/xchart/HorizontalBarSeries.java | 121 +++++++++ .../knowm/xchart/internal/chartpart/Axis.java | 66 +++-- .../xchart/internal/chartpart/AxisPair.java | 11 + .../chartpart/Legend_HorizontalBar.java | 79 ++++++ .../internal/chartpart/PlotContent_.java | 2 +- .../chartpart/PlotContent_HorizontalBar.java | 255 ++++++++++++++++++ .../chartpart/Plot_HorizontalBar.java | 19 ++ .../xchart/internal/chartpart/ToolTips.java | 12 +- .../xchart/style/HorizontalBarStyler.java | 188 +++++++++++++ 16 files changed, 1327 insertions(+), 32 deletions(-) create mode 100644 xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart01.java create mode 100644 xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart02.java create mode 100644 xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart03.java create mode 100644 xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart04.java create mode 100644 xchart/src/main/java/org/knowm/xchart/HorizontalBarChart.java create mode 100644 xchart/src/main/java/org/knowm/xchart/HorizontalBarChartBuilder.java create mode 100644 xchart/src/main/java/org/knowm/xchart/HorizontalBarSeries.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/chartpart/Legend_HorizontalBar.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/chartpart/PlotContent_HorizontalBar.java create mode 100644 xchart/src/main/java/org/knowm/xchart/internal/chartpart/Plot_HorizontalBar.java create mode 100644 xchart/src/main/java/org/knowm/xchart/style/HorizontalBarStyler.java diff --git a/README.md b/README.md index b356a1cf..ce7ea9ec 100644 --- a/README.md +++ b/README.md @@ -119,6 +119,7 @@ repaint. * [x] Area charts * [x] Step Area charts * [x] Bar charts +* [x] Horizontal bar charts * [x] Histogram charts * [x] Pie charts * [x] Donut charts @@ -151,17 +152,18 @@ repaint. Currently, there are 5 major chart types. Each type has its corresponding `ChartBuilder`, `Styler` and `Series`. -| Chart Type | Builder | Styler | Series | Allowed Data Types | Default Series Render Style | -|---------------|----------------------|----------------|----------------|----------------------|-----------------------------| -| XYChart | XYChartBuilder | XYStyler | XYSeries | Number, Date | Line | -| CategoryChart | CategoryChartBuilder | CategoryStyler | CategorySeries | Number, Date, String | Bar | -| PieChart | PieChartBuilder | PieStyler | PieSeries | String | Pie | -| BubbleChart | BubbleChartBuilder | BubbleStyler | BubbleSeries | Number, Date | Round | -| DialChart | DialChartBuilder | DialStyler | DialSeries | double | Round | -| RadarChart | RadarChartBuilder | RadarStyler | RadarSeries | double[] | Round | -| OHLCChart | OHLCChartBuilder | OHLCStyler | OHLCSeries | OHLC with Date | Candle | -| BoxChart | BoxChartBuilder | BoxStyler | BoxSeries | Number, Date, String | Box | -| HeatMapChart | HeatMapChartBuilder | HeatMapStyler | HeatMapSeries | Number, Date, String | -- | +| Chart Type | Builder | Styler | Series | Allowed Data Types | Default Series Render Style | +|--------------------|---------------------------|---------------------|---------------------|----------------------|-----------------------------| +| XYChart | XYChartBuilder | XYStyler | XYSeries | Number, Date | Line | +| CategoryChart | CategoryChartBuilder | CategoryStyler | CategorySeries | Number, Date, String | Bar | +| PieChart | PieChartBuilder | PieStyler | PieSeries | String | Pie | +| BubbleChart | BubbleChartBuilder | BubbleStyler | BubbleSeries | Number, Date | Round | +| DialChart | DialChartBuilder | DialStyler | DialSeries | double | Round | +| RadarChart | RadarChartBuilder | RadarStyler | RadarSeries | double[] | Round | +| OHLCChart | OHLCChartBuilder | OHLCStyler | OHLCSeries | OHLC with Date | Candle | +| BoxChart | BoxChartBuilder | BoxStyler | BoxSeries | Number, Date, String | Box | +| HeatMapChart | HeatMapChartBuilder | HeatMapStyler | HeatMapSeries | Number, Date, String | -- | +| HorizontalBarChart | HorizontalBarChartBuilder | HorizontalBarStyler | HorizontalBarSeries | Number, Date, String | Bar | The different Stylers contain chart styling methods specific to the corresponding chart type as well as common styling methods common across all chart types. @@ -284,6 +286,16 @@ An example of a set of sequence numbers: 12, 15, 17, 19, 20, 23, 25, 28, 30, 33, `HeatMapChart` take Date, Number or String data types for the X-Axis, Y-Axis. +### HorizontalBarChart + +![](https://raw.githubusercontent.com/knowm/XChart/develop/etc/XChart_HorizontalBarChart.png) + +`HorizontalBarChart` charts take Date, Number or String data types for the Y-Axis and Number data types for the X-Axis. For the Y-Axis, each category is given its own tick mark. + +It supports `labels` and `tooltips`, but more advanced features like `error bars` or `stacking` are not yet implemented. + +Series render style is `Bar`. + ## Real-time Java Charts using XChart ![](https://raw.githubusercontent.com/knowm/XChart/develop/etc/XChart_SimpleRealtime.gif) diff --git a/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart01.java b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart01.java new file mode 100644 index 00000000..a807a85b --- /dev/null +++ b/xchart-demo/src/main/java/org/knowm/xchart/demo/charts/horizontalbar/HorizontalBarChart01.java @@ -0,0 +1,61 @@ +package org.knowm.xchart.demo.charts.horizontalbar; + +import org.knowm.xchart.HorizontalBarChart; +import org.knowm.xchart.HorizontalBarChartBuilder; +import org.knowm.xchart.SwingWrapper; +import org.knowm.xchart.demo.charts.ExampleChart; +import org.knowm.xchart.style.Styler.LegendPosition; + +import java.util.Arrays; + +/** + * Basic Horizontal Bar Chart + * + *

Demonstrates the following: + * + *