or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

axes-scales.mdchart-creation.mddata-management.mdexport-display.mdindex.mdlabels-tooltips-legends.mdplots-customization.mdrendering-styling.md

chart-creation.mddocs/

0

# Chart Creation

1

2

Factory methods for creating all major chart types with sensible defaults. The ChartFactory class provides static methods that handle the complex setup of plots, renderers, and datasets, allowing developers to create professional charts with minimal code.

3

4

## Capabilities

5

6

### Pie Charts

7

8

Create pie charts for displaying categorical data as portions of a whole.

9

10

```java { .api }

11

/**

12

* Creates a pie chart with default settings

13

* @param title the chart title

14

* @param dataset the data for the chart

15

* @return a pie chart

16

*/

17

public static JFreeChart createPieChart(String title, PieDataset dataset);

18

19

/**

20

* Creates a pie chart with full customization options

21

* @param title the chart title

22

* @param dataset the data for the chart

23

* @param legend flag indicating whether or not a legend is required

24

* @param tooltips configure chart to generate tool tips

25

* @param urls configure chart to generate URLs

26

* @return a pie chart

27

*/

28

public static JFreeChart createPieChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls);

29

30

/**

31

* Creates a ring chart (donut chart) with customization options

32

* @param title the chart title

33

* @param dataset the data for the chart

34

* @param legend flag indicating whether or not a legend is required

35

* @param tooltips configure chart to generate tool tips

36

* @param urls configure chart to generate URLs

37

* @return a ring chart

38

*/

39

public static JFreeChart createRingChart(String title, PieDataset dataset, boolean legend, boolean tooltips, boolean urls);

40

41

/**

42

* Creates multiple pie charts from category data

43

* @param title the chart title

44

* @param dataset the dataset (CategoryDataset)

45

* @param order the order that the data is extracted (by row or by column)

46

* @param legend flag indicating whether or not a legend is required

47

* @param tooltips configure chart to generate tool tips

48

* @param urls configure chart to generate URLs

49

* @return a chart containing multiple pie charts

50

*/

51

public static JFreeChart createMultiplePieChart(String title, CategoryDataset dataset, TableOrder order, boolean legend, boolean tooltips, boolean urls);

52

53

/**

54

* Creates a 3D pie chart (deprecated - use regular pie chart instead)

55

* @param title the chart title

56

* @param dataset the data for the chart

57

* @return a 3D pie chart

58

* @deprecated Use createPieChart() instead

59

*/

60

@Deprecated

61

public static JFreeChart createPieChart3D(String title, PieDataset dataset);

62

```

63

64

**Usage Examples:**

65

66

```java

67

import org.jfree.chart.ChartFactory;

68

import org.jfree.data.general.DefaultPieDataset;

69

70

// Create dataset

71

DefaultPieDataset<String> dataset = new DefaultPieDataset<>();

72

dataset.setValue("Chrome", 65.2);

73

dataset.setValue("Firefox", 18.7);

74

dataset.setValue("Safari", 9.6);

75

dataset.setValue("Edge", 4.8);

76

dataset.setValue("Other", 1.7);

77

78

// Create simple pie chart

79

JFreeChart chart = ChartFactory.createPieChart(

80

"Browser Market Share", dataset);

81

82

// Create pie chart with all options

83

JFreeChart chartWithOptions = ChartFactory.createPieChart(

84

"Browser Market Share", dataset, true, true, false);

85

86

// Create ring chart

87

JFreeChart ringChart = ChartFactory.createRingChart(

88

"Browser Market Share", dataset, true, true, false);

89

```

90

91

### Bar Charts

92

93

Create bar charts for comparing categorical data with rectangular bars.

94

95

```java { .api }

96

/**

97

* Creates a bar chart with default settings

98

* @param title the chart title

99

* @param categoryAxisLabel the label for the category axis

100

* @param valueAxisLabel the label for the value axis

101

* @param dataset the dataset for the chart

102

* @return a bar chart

103

*/

104

public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset);

105

106

/**

107

* Creates a bar chart with full customization options

108

* @param title the chart title

109

* @param categoryAxisLabel the label for the category axis

110

* @param valueAxisLabel the label for the value axis

111

* @param dataset the dataset for the chart

112

* @param orientation the plot orientation (horizontal or vertical)

113

* @param legend flag indicating whether or not a legend is required

114

* @param tooltips configure chart to generate tool tips

115

* @param urls configure chart to generate URLs

116

* @return a bar chart

117

*/

118

public static JFreeChart createBarChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

119

120

/**

121

* Creates a 3D bar chart

122

* @param title the chart title

123

* @param categoryAxisLabel the label for the category axis

124

* @param valueAxisLabel the label for the value axis

125

* @param dataset the dataset for the chart

126

* @param orientation the plot orientation (horizontal or vertical)

127

* @param legend flag indicating whether or not a legend is required

128

* @param tooltips configure chart to generate tool tips

129

* @param urls configure chart to generate URLs

130

* @return a 3D bar chart

131

*/

132

public static JFreeChart createBarChart3D(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

133

134

/**

135

* Creates a stacked bar chart

136

* @param title the chart title

137

* @param domainAxisLabel the label for the category axis

138

* @param rangeAxisLabel the label for the value axis

139

* @param dataset the dataset for the chart

140

* @return a stacked bar chart

141

*/

142

public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset);

143

144

/**

145

* Creates a stacked bar chart with full customization options

146

* @param title the chart title

147

* @param domainAxisLabel the label for the category axis

148

* @param rangeAxisLabel the label for the value axis

149

* @param dataset the dataset for the chart

150

* @param orientation the plot orientation (horizontal or vertical)

151

* @param legend flag indicating whether or not a legend is required

152

* @param tooltips configure chart to generate tool tips

153

* @param urls configure chart to generate URLs

154

* @return a stacked bar chart

155

*/

156

public static JFreeChart createStackedBarChart(String title, String domainAxisLabel, String rangeAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

157

158

/**

159

* Creates a waterfall chart showing cumulative effects

160

* @param title the chart title

161

* @param categoryAxisLabel the label for the category axis

162

* @param valueAxisLabel the label for the value axis

163

* @param dataset the dataset for the chart

164

* @param orientation the plot orientation (horizontal or vertical)

165

* @param legend flag indicating whether or not a legend is required

166

* @param tooltips configure chart to generate tool tips

167

* @param urls configure chart to generate URLs

168

* @return a waterfall chart

169

*/

170

public static JFreeChart createWaterfallChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

171

```

172

173

**Usage Examples:**

174

175

```java

176

import org.jfree.chart.ChartFactory;

177

import org.jfree.data.category.DefaultCategoryDataset;

178

179

// Create dataset

180

DefaultCategoryDataset dataset = new DefaultCategoryDataset();

181

dataset.addValue(100, "Q1", "Jan");

182

dataset.addValue(150, "Q1", "Feb");

183

dataset.addValue(120, "Q1", "Mar");

184

dataset.addValue(110, "Q2", "Jan");

185

dataset.addValue(180, "Q2", "Feb");

186

dataset.addValue(140, "Q2", "Mar");

187

188

// Create simple bar chart

189

JFreeChart chart = ChartFactory.createBarChart(

190

"Quarterly Sales", "Month", "Sales ($000)", dataset);

191

192

// Create horizontal bar chart

193

JFreeChart horizontalChart = ChartFactory.createBarChart(

194

"Quarterly Sales", "Month", "Sales ($000)", dataset,

195

PlotOrientation.HORIZONTAL, true, true, false);

196

197

// Create stacked bar chart

198

JFreeChart stackedChart = ChartFactory.createStackedBarChart(

199

"Quarterly Sales", "Month", "Sales ($000)", dataset);

200

```

201

202

### Line Charts

203

204

Create line charts for displaying trends over categories or continuous data.

205

206

```java { .api }

207

/**

208

* Creates a line chart with default settings

209

* @param title the chart title

210

* @param categoryAxisLabel the label for the category axis

211

* @param valueAxisLabel the label for the value axis

212

* @param dataset the dataset for the chart

213

* @return a line chart

214

*/

215

public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset);

216

217

/**

218

* Creates a line chart with full customization options

219

* @param title the chart title

220

* @param categoryAxisLabel the label for the category axis

221

* @param valueAxisLabel the label for the value axis

222

* @param dataset the dataset for the chart

223

* @param orientation the plot orientation (horizontal or vertical)

224

* @param legend flag indicating whether or not a legend is required

225

* @param tooltips configure chart to generate tool tips

226

* @param urls configure chart to generate URLs

227

* @return a line chart

228

*/

229

public static JFreeChart createLineChart(String title, String categoryAxisLabel, String valueAxisLabel, CategoryDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

230

231

/**

232

* Creates a time series chart for displaying data over time

233

* @param title the chart title

234

* @param timeAxisLabel the label for the time axis

235

* @param valueAxisLabel the label for the value axis

236

* @param dataset the dataset for the chart

237

* @return a time series chart

238

*/

239

public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset);

240

241

/**

242

* Creates a time series chart with full customization options

243

* @param title the chart title

244

* @param timeAxisLabel the label for the time axis

245

* @param valueAxisLabel the label for the value axis

246

* @param dataset the dataset for the chart

247

* @param legend flag indicating whether or not a legend is required

248

* @param tooltips configure chart to generate tool tips

249

* @param urls configure chart to generate URLs

250

* @return a time series chart

251

*/

252

public static JFreeChart createTimeSeriesChart(String title, String timeAxisLabel, String valueAxisLabel, XYDataset dataset, boolean legend, boolean tooltips, boolean urls);

253

```

254

255

**Usage Examples:**

256

257

```java

258

import org.jfree.chart.ChartFactory;

259

import org.jfree.data.time.*;

260

261

// Create time series dataset

262

TimeSeries series1 = new TimeSeries("Stock Price");

263

series1.add(new Day(1, 1, 2023), 100.0);

264

series1.add(new Day(2, 1, 2023), 105.0);

265

series1.add(new Day(3, 1, 2023), 102.0);

266

series1.add(new Day(4, 1, 2023), 108.0);

267

268

TimeSeriesCollection dataset = new TimeSeriesCollection();

269

dataset.addSeries(series1);

270

271

// Create time series chart

272

JFreeChart chart = ChartFactory.createTimeSeriesChart(

273

"Stock Price History", "Date", "Price ($)", dataset);

274

```

275

276

### XY Charts

277

278

Create XY charts for displaying relationships between two continuous variables.

279

280

```java { .api }

281

/**

282

* Creates a scatter plot

283

* @param title the chart title

284

* @param xAxisLabel the label for the X axis

285

* @param yAxisLabel the label for the Y axis

286

* @param dataset the dataset for the chart

287

* @return a scatter plot

288

*/

289

public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset);

290

291

/**

292

* Creates a scatter plot with full customization options

293

* @param title the chart title

294

* @param xAxisLabel the label for the X axis

295

* @param yAxisLabel the label for the Y axis

296

* @param dataset the dataset for the chart

297

* @param orientation the plot orientation (horizontal or vertical)

298

* @param legend flag indicating whether or not a legend is required

299

* @param tooltips configure chart to generate tool tips

300

* @param urls configure chart to generate URLs

301

* @return a scatter plot

302

*/

303

public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

304

305

/**

306

* Creates an XY line chart

307

* @param title the chart title

308

* @param xAxisLabel the label for the X axis

309

* @param yAxisLabel the label for the Y axis

310

* @param dataset the dataset for the chart

311

* @return an XY line chart

312

*/

313

public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset);

314

315

/**

316

* Creates an XY area chart

317

* @param title the chart title

318

* @param xAxisLabel the label for the X axis

319

* @param yAxisLabel the label for the Y axis

320

* @param dataset the dataset for the chart

321

* @return an XY area chart

322

*/

323

public static JFreeChart createXYAreaChart(String title, String xAxisLabel, String yAxisLabel, XYDataset dataset);

324

325

/**

326

* Creates an XY bar chart

327

* @param title the chart title

328

* @param xAxisLabel the label for the X axis

329

* @param dateAxis flag indicating whether the X axis should be formatted as a date axis

330

* @param yAxisLabel the label for the Y axis

331

* @param dataset the dataset for the chart

332

* @param orientation the plot orientation (horizontal or vertical)

333

* @param legend flag indicating whether or not a legend is required

334

* @param tooltips configure chart to generate tool tips

335

* @param urls configure chart to generate URLs

336

* @return an XY bar chart

337

*/

338

public static JFreeChart createXYBarChart(String title, String xAxisLabel, boolean dateAxis, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

339

340

/**

341

* Creates a bubble chart for displaying three-dimensional data

342

* @param title the chart title

343

* @param xAxisLabel the label for the X axis

344

* @param yAxisLabel the label for the Y axis

345

* @param dataset the dataset for the chart (must be XYZDataset)

346

* @param orientation the plot orientation (horizontal or vertical)

347

* @param legend flag indicating whether or not a legend is required

348

* @param tooltips configure chart to generate tool tips

349

* @param urls configure chart to generate URLs

350

* @return a bubble chart

351

*/

352

public static JFreeChart createBubbleChart(String title, String xAxisLabel, String yAxisLabel, XYZDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

353

```

354

355

**Usage Examples:**

356

357

```java

358

import org.jfree.chart.ChartFactory;

359

import org.jfree.data.xy.*;

360

361

// Create XY dataset

362

XYSeries series = new XYSeries("Data Points");

363

series.add(1.0, 2.0);

364

series.add(2.0, 3.5);

365

series.add(3.0, 2.8);

366

series.add(4.0, 4.1);

367

series.add(5.0, 3.9);

368

369

XYSeriesCollection dataset = new XYSeriesCollection();

370

dataset.addSeries(series);

371

372

// Create scatter plot

373

JFreeChart scatterChart = ChartFactory.createScatterPlot(

374

"XY Data", "X Values", "Y Values", dataset);

375

376

// Create XY line chart

377

JFreeChart lineChart = ChartFactory.createXYLineChart(

378

"XY Data", "X Values", "Y Values", dataset);

379

```

380

381

### Specialized Charts

382

383

Create specialized charts for specific use cases like financial data, statistical analysis, and scientific visualization.

384

385

```java { .api }

386

/**

387

* Creates a candlestick chart for financial data

388

* @param title the chart title

389

* @param timeAxisLabel the label for the time axis

390

* @param valueAxisLabel the label for the value axis

391

* @param dataset the dataset for the chart (must be OHLCDataset)

392

* @param legend flag indicating whether or not a legend is required

393

* @return a candlestick chart

394

*/

395

public static JFreeChart createCandlestickChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend);

396

397

/**

398

* Creates a high-low chart for financial data

399

* @param title the chart title

400

* @param timeAxisLabel the label for the time axis

401

* @param valueAxisLabel the label for the value axis

402

* @param dataset the dataset for the chart (must be HighLowDataset)

403

* @param legend flag indicating whether or not a legend is required

404

* @return a high-low chart

405

*/

406

public static JFreeChart createHighLowChart(String title, String timeAxisLabel, String valueAxisLabel, OHLCDataset dataset, boolean legend);

407

408

/**

409

* Creates a box and whisker chart for statistical data

410

* @param title the chart title

411

* @param categoryAxisLabel the label for the category axis

412

* @param valueAxisLabel the label for the value axis

413

* @param dataset the dataset for the chart (must be BoxAndWhiskerCategoryDataset)

414

* @param legend flag indicating whether or not a legend is required

415

* @return a box and whisker chart

416

*/

417

public static JFreeChart createBoxAndWhiskerChart(String title, String categoryAxisLabel, String valueAxisLabel, BoxAndWhiskerCategoryDataset dataset, boolean legend);

418

419

/**

420

* Creates a box and whisker chart for time series statistical data

421

* @param title the chart title

422

* @param timeAxisLabel the label for the time axis

423

* @param valueAxisLabel the label for the value axis

424

* @param dataset the dataset for the chart (must be BoxAndWhiskerXYDataset)

425

* @param legend flag indicating whether or not a legend is required

426

* @return a box and whisker chart

427

*/

428

public static JFreeChart createBoxAndWhiskerChart(String title, String timeAxisLabel, String valueAxisLabel, BoxAndWhiskerXYDataset dataset, boolean legend);

429

430

/**

431

* Creates a histogram

432

* @param title the chart title

433

* @param xAxisLabel the label for the X axis

434

* @param yAxisLabel the label for the Y axis

435

* @param dataset the dataset for the chart (must be IntervalXYDataset)

436

* @param orientation the plot orientation (horizontal or vertical)

437

* @param legend flag indicating whether or not a legend is required

438

* @param tooltips configure chart to generate tool tips

439

* @param urls configure chart to generate URLs

440

* @return a histogram

441

*/

442

public static JFreeChart createHistogram(String title, String xAxisLabel, String yAxisLabel, IntervalXYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

443

444

/**

445

* Creates a polar chart

446

* @param title the chart title

447

* @param dataset the dataset for the chart

448

* @param legend flag indicating whether or not a legend is required

449

* @param tooltips configure chart to generate tool tips

450

* @param urls configure chart to generate URLs

451

* @return a polar chart

452

*/

453

public static JFreeChart createPolarChart(String title, XYDataset dataset, boolean legend, boolean tooltips, boolean urls);

454

455

/**

456

* Creates a Gantt chart for project management

457

* @param title the chart title

458

* @param categoryAxisLabel the label for the category axis

459

* @param dateAxisLabel the label for the date axis

460

* @param dataset the dataset for the chart (must be IntervalCategoryDataset)

461

* @param legend flag indicating whether or not a legend is required

462

* @param tooltips configure chart to generate tool tips

463

* @param urls configure chart to generate URLs

464

* @return a Gantt chart

465

*/

466

public static JFreeChart createGanttChart(String title, String categoryAxisLabel, String dateAxisLabel, IntervalCategoryDataset dataset, boolean legend, boolean tooltips, boolean urls);

467

468

/**

469

* Creates a wind plot for displaying wind direction and force data

470

* @param title the chart title

471

* @param xAxisLabel the label for the X axis

472

* @param yAxisLabel the label for the Y axis

473

* @param dataset the dataset for the chart (must be WindDataset)

474

* @param legend flag indicating whether or not a legend is required

475

* @param tooltips configure chart to generate tool tips

476

* @param urls configure chart to generate URLs

477

* @return a wind plot

478

*/

479

public static JFreeChart createWindPlot(String title, String xAxisLabel, String yAxisLabel, WindDataset dataset, boolean legend, boolean tooltips, boolean urls);

480

481

/**

482

* Creates a wafer map chart for semiconductor wafer analysis

483

* @param title the chart title

484

* @param dataset the dataset for the chart (must be WaferMapDataset)

485

* @param orientation the plot orientation (horizontal or vertical)

486

* @param legend flag indicating whether or not a legend is required

487

* @param tooltips configure chart to generate tool tips

488

* @param urls configure chart to generate URLs

489

* @return a wafer map chart

490

*/

491

public static JFreeChart createWaferMapChart(String title, WaferMapDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls);

492

```

493

494

## Chart Theme Management

495

496

```java { .api }

497

/**

498

* Gets the current chart theme used by the factory methods

499

* @return the chart theme

500

*/

501

public static ChartTheme getChartTheme();

502

503

/**

504

* Sets the chart theme to be used by the factory methods

505

* @param theme the new chart theme

506

*/

507

public static void setChartTheme(ChartTheme theme);

508

```

509

510

**Usage Example:**

511

512

```java

513

import org.jfree.chart.StandardChartTheme;

514

515

// Apply a custom theme to all new charts

516

ChartFactory.setChartTheme(new StandardChartTheme("Custom"));

517

518

// Create chart with custom theme

519

JFreeChart chart = ChartFactory.createBarChart(

520

"Sales Data", "Month", "Revenue", dataset);

521

```