This looks like a stacked bar chart, which you could achieve with the configureChart
extension function without too much trouble. Look around on this forum for topics that mention JFreeChart and see what you can find.
@PGriffith this is what I came up but still unable to get the desired result
from java.awt import Color
from org.jfree.chart.plot import PlotOrientation
from org.jfree.chart import ChartFactory
from org.jfree.chart.renderer.category import LineAndShapeRenderer
from org.jfree.data.category import DefaultCategoryDataset
from org.jfree.chart.plot import CategoryPlot
# Create a dataset
dataset = DefaultCategoryDataset()
# Add data to the dataset
dataset.addValue(1.0, "Series 1", "Category 1")
dataset.addValue(4.0, "Series 1", "Category 2")
dataset.addValue(3.0, "Series 1", "Category 3")
dataset.addValue(5.0, "Series 1", "Category 4")
dataset.addValue(5.0, "Series 1", "Category 5")
# Create a line chart
chart = ChartFactory.createLineChart(
"Ribbon Chart",
"Category",
"Value",
dataset,
PlotOrientation.VERTICAL,
True,
True,
False
)
# Set custom colors for lines
renderer = LineAndShapeRenderer()
renderer.setSeriesPaint(0, Color.RED) # Change color as per your preference
plot = chart.getPlot()
plot.setRenderer(renderer)
Hi, arpit. Please see Wiki - how to post code on this forum. Most of your code got formatted correctly because of four or more leading spaces on the lines but all the imports didn't.
Thanks
The configureChart
extension function gives you an instance of JFreeChart
you have to customize. You don't want to create your own, nor (likely) your own dataset. I don't know where you got that example from (ChatGPT, I'm guessing), but most of the code there isn't suitable for this application.
Try just this code in configureChart
to verify that the function is actually doing anything:
from org.jfree.chart.renderer.category import LineAndShapeRenderer
renderer = LineAndShapeRenderer()
renderer.setSeriesPaint(0, system.gui.color(255, 0, 0))
char.plot.renderer = renderer