# Custom bar chart in reporting

**URL:** <https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192>\
**Category:** Ignition\
**Tags:** ignition81, reporting\
**Created:** [December 24, 2024, 11:16am UTC](https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192 "2024-12-24T11:16:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Govind\_Suthar1](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Govind\_Suthar1](https://forum.inductiveautomation.com/u/Govind_Suthar1)\
**Post date:** [December 24, 2024, 11:16am UTC](https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192/1 "2024-12-24T11:16:56Z")

</div>

Hii all,

Created a report with a bar chart and placed a script in the bar chart. In the Preview tab, check that the x-axis 'ist\_date' is not showing and the y-axis 'total\_totalizer' data is showing.

Created store procedure for the fetch the data from database.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/9/b96ff9672fa7b1561f2eda274a3109b6a76b9ec2.png)

Bar chart configuration.  
Defined data key : 'Monthly'

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f876d485ba68af45eb0e00834f5fd359d17f709.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/6/96309dde341ff49f998e65a786fa4bc12f799642.png)

Configured the script for the custom bar chart.

```python
def configureChart(data, chart):

    from org.jfree.data.category import DefaultCategoryDataset

    # Get the original dataset from the chart
    originalDataset = chart.getCategoryPlot().getDataset()
    
    # Create a new dataset
    filteredDataset = DefaultCategoryDataset()

    # Extract data from the original dataset
    for row in range(originalDataset.getRowCount()):
        for col in range(originalDataset.getColumnCount()):
            category = originalDataset.getColumnKey(col) # Assume this is 'ist_date'
            series = originalDataset.getRowKey(row) # Series name (e.g., 'total_totalizer')
            value = originalDataset.getValue(row, col) # Data value

            # Add only 'total_totalizer' values to the new dataset
            if series == 'total_totalizer' and value is not None:
                # Scale the value by 1000
                filteredDataset.addValue(value * 1000, series, category)

    # Set the new dataset to the chart
    chart.getCategoryPlot().setDataset(filteredDataset)

```

When the preview tab the ist\_date not displayed.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/1/41ec0f5abea57b5d1d4052ed7a22ea74d66ef1b0.png)

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [December 26, 2024, 9:01pm UTC](https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192/2 "2024-12-26T21:01:06Z")

</div>

That looks like the date labels are too big, so the report is hiding them and showing `...` instead. You would need to either decrease font size or format the date shown as the category to make it show less text.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [December 27, 2024, 3:15am UTC](https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192/3 "2024-12-27T03:15:39Z")

</div>

I would rotate the text of x-axis  
After the for loop try this:

```python
from org.jfree.chart.axis import CategoryAxis
from org.jfree.chart.plot import CategoryPlot
from java.awt import Font

...

#chart.getCategoryPlot().setDataset(filteredDataset) #replace this with:
plot = chart.getCategoryPlot()
plot.setDataset(filteredDataset)

#change xaxis 90 degree and size
xAxis = plot.getDomainAxis()
xAxis.setLabel("Date")
xAxis.setCategoryLabelPositions(CategoryAxis.createStandardCategoryLabelPositions().createUpRotationLabelPositions(90))
xAxis.setLabelFont(Font("Arial", Font.BOLD, 10))
xAxis.setTickLabelFont(Font("Arial", Font.PLAIN, 8))

```

---

<div class="post-metadata">

**Author:** ![Govind\_Suthar1](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Govind\_Suthar1](https://forum.inductiveautomation.com/u/Govind_Suthar1)\
**Post date:** [December 30, 2024, 12:40pm UTC](https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192/4 "2024-12-30T12:40:36Z")

</div>

Yes, changed the date format and font size, now it's working.

---

<div class="post-metadata">

**Author:** ![Govind\_Suthar1](https://avatars.discourse-cdn.com/v4/letter/g/a87d85/32.png) [@Govind\_Suthar1](https://forum.inductiveautomation.com/u/Govind_Suthar1)\
**Post date:** [December 30, 2024, 12:56pm UTC](https://forum.inductiveautomation.com/t/custom-bar-chart-in-reporting/100192/5 "2024-12-30T12:56:12Z")

</div>

Yes, but there is an option available to change the x-axis label position.

Thanks for the suggestion.

Now, my second question for the bar label position.

When select the bar label option, the data is displayed on each bar, but it is displayed horizontally.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/5/f584efe993053e3f5782fef7bc4c1d852aa8ef6b.png)

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/d/5de9632cc310177890ef4d1063945f14bf791940.png)

Want to displayed vertically.

Is it possibale to change the bar label position using script?
