Histograms are visual representation of data distribution over a continuous interval or certain time period. These charts comprise vertical bars to indicate the frequency in each interval or bin created by dividing the raw data values into a series of consecutive and non-overlapping intervals. Hence, histograms help in estimating the range where maximum values fall as well as in knowing the extremes and gaps in data values, if there are any. For instance, histogram can help you find the range of height in which maximum students of a particular age group fall.
Refer to the following code to add a Histogram chart.
Java |
Copy Code |
---|---|
private static void HistogramChart() { // Initialize workbook Workbook workbook = new Workbook(); // Fetch default worksheet IWorksheet worksheet = workbook.getWorksheets().get(0); // Prepare data for chart worksheet.getRange("A1:B11") .setValue(new Object[][] { { "Complaint", "Count" }, { "Too noisy", 27 }, { "Overpriced", 789 }, { "Food is tasteless", 65 }, { "Food is not fresh", 19 }, { "Food is too salty", 15 }, { "Not clean", 30 }, { "Unfriendly staff", 12 }, { "Wait time", 109 }, { "No atmosphere", 45 }, { "Small portions", 621 } }); worksheet.getRange("A:B").getColumns().autoFit(); // Add Histogram Chart IShape histogramchartShape = worksheet.getShapes().addChart(ChartType.Histogram, 300, 30, 300, 250); // Set range"A1:B11" as the histogram chart series histogramchartShape.getChart().getSeriesCollection().add(worksheet.getRange("A1:B11")); // Sets bins type by category histogramchartShape.getChart().getChartGroups().get(0).setBinsType(BinsType.BinsTypeCategorical); // Configure Chart Title histogramchartShape.getChart().getChartTitle().setText("Histogram Chart"); // Saving workbook to Xlsx workbook.save("29-HistogramChart.xlsx", SaveFileFormat.Xlsx); |