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

data-management.mddocs/

0

# Data Management

1

2

Dataset interfaces and implementations for providing data to charts. JFreeChart uses a flexible dataset architecture that supports different data types and structures, enabling everything from simple category data to complex time series and 3D datasets.

3

4

## Capabilities

5

6

### Dataset Base Interface

7

8

Common functionality for all dataset types including change notification and grouping.

9

10

```java { .api }

11

/**

12

* Base interface for all datasets

13

*/

14

public interface Dataset {

15

/**

16

* Registers a change listener with the dataset

17

* @param listener the listener to be registered

18

*/

19

public void addChangeListener(DatasetChangeListener listener);

20

21

/**

22

* Deregisters a change listener from the dataset

23

* @param listener the listener to be deregistered

24

*/

25

public void removeChangeListener(DatasetChangeListener listener);

26

27

/**

28

* Returns the dataset group

29

* @return the dataset group (possibly null)

30

*/

31

public DatasetGroup getGroup();

32

33

/**

34

* Sets the dataset group

35

* @param group the group

36

*/

37

public void setGroup(DatasetGroup group);

38

}

39

40

/**

41

* Base interface for datasets containing multiple data series

42

*/

43

public interface SeriesDataset extends Dataset {

44

/**

45

* Returns the number of series in the dataset

46

* @return the series count

47

*/

48

public int getSeriesCount();

49

50

/**

51

* Returns the key for a series

52

* @param series the series index (zero-based)

53

* @return the series key

54

*/

55

public Comparable getSeriesKey(int series);

56

57

/**

58

* Returns the index of the series with the specified key

59

* @param seriesKey the series key

60

* @return the series index, or -1 if not found

61

*/

62

public int indexOf(Comparable seriesKey);

63

}

64

```

65

66

### Category Datasets

67

68

Datasets for category-based charts like bar charts and line charts, organizing data in rows and columns.

69

70

```java { .api }

71

/**

72

* Interface for datasets containing category data (extends KeyedValues2D)

73

*/

74

public interface CategoryDataset extends KeyedValues2D, Dataset {

75

// Inherited from KeyedValues2D:

76

77

/**

78

* Returns the number of rows (series) in the dataset

79

* @return the row count

80

*/

81

public int getRowCount();

82

83

/**

84

* Returns the number of columns (categories) in the dataset

85

* @return the column count

86

*/

87

public int getColumnCount();

88

89

/**

90

* Returns a value from the dataset

91

* @param row the row index (zero-based)

92

* @param column the column index (zero-based)

93

* @return the value (possibly null)

94

*/

95

public Number getValue(int row, int column);

96

97

/**

98

* Returns a value from the dataset using keys

99

* @param rowKey the row key

100

* @param columnKey the column key

101

* @return the value (possibly null)

102

*/

103

public Number getValue(Comparable rowKey, Comparable columnKey);

104

105

/**

106

* Returns the key for the specified row

107

* @param row the row index (zero-based)

108

* @return the row key

109

*/

110

public Comparable getRowKey(int row);

111

112

/**

113

* Returns the key for the specified column

114

* @param column the column index (zero-based)

115

* @return the column key

116

*/

117

public Comparable getColumnKey(int column);

118

119

/**

120

* Returns the row keys

121

* @return a list of row keys

122

*/

123

public List getRowKeys();

124

125

/**

126

* Returns the column keys

127

* @return a list of column keys

128

*/

129

public List getColumnKeys();

130

131

/**

132

* Returns the row index for a given key

133

* @param key the row key

134

* @return the row index, or -1 if not found

135

*/

136

public int getRowIndex(Comparable key);

137

138

/**

139

* Returns the column index for a given key

140

* @param key the column key

141

* @return the column index, or -1 if not found

142

*/

143

public int getColumnIndex(Comparable key);

144

}

145

146

/**

147

* Default implementation of CategoryDataset

148

*/

149

public class DefaultCategoryDataset implements CategoryDataset {

150

/**

151

* Creates a new empty dataset

152

*/

153

public DefaultCategoryDataset();

154

155

/**

156

* Adds a value to the dataset

157

* @param value the value

158

* @param rowKey the row key

159

* @param columnKey the column key

160

*/

161

public void addValue(Number value, Comparable rowKey, Comparable columnKey);

162

163

/**

164

* Adds a value to the dataset

165

* @param value the value

166

* @param rowKey the row key

167

* @param columnKey the column key

168

*/

169

public void addValue(double value, Comparable rowKey, Comparable columnKey);

170

171

/**

172

* Updates an existing value in the dataset

173

* @param value the new value

174

* @param rowKey the row key

175

* @param columnKey the column key

176

*/

177

public void setValue(Number value, Comparable rowKey, Comparable columnKey);

178

179

/**

180

* Removes a value from the dataset

181

* @param rowKey the row key

182

* @param columnKey the column key

183

*/

184

public void removeValue(Comparable rowKey, Comparable columnKey);

185

186

/**

187

* Removes an entire row from the dataset

188

* @param rowKey the row key

189

*/

190

public void removeRow(Comparable rowKey);

191

192

/**

193

* Removes an entire column from the dataset

194

* @param columnKey the column key

195

*/

196

public void removeColumn(Comparable columnKey);

197

198

/**

199

* Clears all data from the dataset

200

*/

201

public void clear();

202

}

203

204

/**

205

* Category dataset with interval values (start and end values)

206

*/

207

public interface IntervalCategoryDataset extends CategoryDataset {

208

/**

209

* Returns the start value for an item

210

* @param row the row index

211

* @param column the column index

212

* @return the start value

213

*/

214

public Number getStartValue(int row, int column);

215

216

/**

217

* Returns the start value for an item using keys

218

* @param rowKey the row key

219

* @param columnKey the column key

220

* @return the start value

221

*/

222

public Number getStartValue(Comparable rowKey, Comparable columnKey);

223

224

/**

225

* Returns the end value for an item

226

* @param row the row index

227

* @param column the column index

228

* @return the end value

229

*/

230

public Number getEndValue(int row, int column);

231

232

/**

233

* Returns the end value for an item using keys

234

* @param rowKey the row key

235

* @param columnKey the column key

236

* @return the end value

237

*/

238

public Number getEndValue(Comparable rowKey, Comparable columnKey);

239

}

240

```

241

242

**Usage Example:**

243

244

```java

245

import org.jfree.data.category.DefaultCategoryDataset;

246

247

// Create and populate category dataset

248

DefaultCategoryDataset dataset = new DefaultCategoryDataset();

249

250

// Add data for quarterly sales

251

dataset.addValue(100.0, "Q1 2023", "Product A");

252

dataset.addValue(150.0, "Q1 2023", "Product B");

253

dataset.addValue(120.0, "Q1 2023", "Product C");

254

255

dataset.addValue(110.0, "Q2 2023", "Product A");

256

dataset.addValue(180.0, "Q2 2023", "Product B");

257

dataset.addValue(140.0, "Q2 2023", "Product C");

258

259

// Access data

260

Number value = dataset.getValue("Q1 2023", "Product A"); // 100.0

261

int rowCount = dataset.getRowCount(); // 2 quarters

262

int columnCount = dataset.getColumnCount(); // 3 products

263

264

// Remove specific data

265

dataset.removeValue("Q1 2023", "Product C");

266

267

// Clear all data

268

dataset.clear();

269

```

270

271

### XY Datasets

272

273

Datasets for XY coordinate data such as scatter plots, line charts, and time series.

274

275

```java { .api }

276

/**

277

* Interface for XY coordinate datasets

278

*/

279

public interface XYDataset extends SeriesDataset {

280

/**

281

* Returns the order of the domain (X) values

282

* @return the domain order

283

*/

284

public DomainOrder getDomainOrder();

285

286

/**

287

* Returns the number of items in a series

288

* @param series the series index (zero-based)

289

* @return the item count

290

*/

291

public int getItemCount(int series);

292

293

/**

294

* Returns the X value for a data item

295

* @param series the series index (zero-based)

296

* @param item the item index (zero-based)

297

* @return the X value (possibly null)

298

*/

299

public Number getX(int series, int item);

300

301

/**

302

* Returns the Y value for a data item

303

* @param series the series index (zero-based)

304

* @param item the item index (zero-based)

305

* @return the Y value (possibly null)

306

*/

307

public Number getY(int series, int item);

308

309

/**

310

* Returns the X value as a double primitive

311

* @param series the series index (zero-based)

312

* @param item the item index (zero-based)

313

* @return the X value as double

314

*/

315

public double getXValue(int series, int item);

316

317

/**

318

* Returns the Y value as a double primitive

319

* @param series the series index (zero-based)

320

* @param item the item index (zero-based)

321

* @return the Y value as double

322

*/

323

public double getYValue(int series, int item);

324

}

325

326

/**

327

* XY dataset with interval values

328

*/

329

public interface IntervalXYDataset extends XYDataset {

330

/**

331

* Returns the start X value for an item

332

* @param series the series index

333

* @param item the item index

334

* @return the start X value

335

*/

336

public Number getStartX(int series, int item);

337

338

/**

339

* Returns the end X value for an item

340

* @param series the series index

341

* @param item the item index

342

* @return the end X value

343

*/

344

public Number getEndX(int series, int item);

345

346

/**

347

* Returns the start Y value for an item

348

* @param series the series index

349

* @param item the item index

350

* @return the start Y value

351

*/

352

public Number getStartY(int series, int item);

353

354

/**

355

* Returns the end Y value for an item

356

* @param series the series index

357

* @param item the item index

358

* @return the end Y value

359

*/

360

public Number getEndY(int series, int item);

361

362

// Primitive versions for performance

363

public double getStartXValue(int series, int item);

364

public double getEndXValue(int series, int item);

365

public double getStartYValue(int series, int item);

366

public double getEndYValue(int series, int item);

367

}

368

369

/**

370

* XY dataset with Z (third dimension) values for bubble charts

371

*/

372

public interface XYZDataset extends XYDataset {

373

/**

374

* Returns the Z value for a data item

375

* @param series the series index (zero-based)

376

* @param item the item index (zero-based)

377

* @return the Z value (possibly null)

378

*/

379

public Number getZ(int series, int item);

380

381

/**

382

* Returns the Z value as a double primitive

383

* @param series the series index (zero-based)

384

* @param item the item index (zero-based)

385

* @return the Z value as double

386

*/

387

public double getZValue(int series, int item);

388

}

389

390

/**

391

* Collection of XY series for creating multi-series XY datasets

392

*/

393

public class XYSeriesCollection implements XYDataset, IntervalXYDataset {

394

/**

395

* Creates a new empty collection

396

*/

397

public XYSeriesCollection();

398

399

/**

400

* Adds a series to the collection

401

* @param series the series

402

*/

403

public void addSeries(XYSeries series);

404

405

/**

406

* Removes a series from the collection

407

* @param series the series

408

*/

409

public void removeSeries(XYSeries series);

410

411

/**

412

* Removes a series by index

413

* @param series the series index

414

*/

415

public void removeSeries(int series);

416

417

/**

418

* Removes all series from the collection

419

*/

420

public void removeAllSeries();

421

422

/**

423

* Returns a series by index

424

* @param series the series index

425

* @return the series

426

*/

427

public XYSeries getSeries(int series);

428

429

/**

430

* Returns a series by key

431

* @param key the series key

432

* @return the series, or null if not found

433

*/

434

public XYSeries getSeries(Comparable key);

435

436

/**

437

* Returns the series index for a given key

438

* @param key the series key

439

* @return the series index, or -1 if not found

440

*/

441

public int indexOf(Comparable key);

442

}

443

444

/**

445

* Individual XY data series

446

*/

447

public class XYSeries implements Cloneable, Serializable {

448

/**

449

* Creates a new XY series

450

* @param key the series key

451

*/

452

public XYSeries(Comparable key);

453

454

/**

455

* Creates a new XY series with auto-sorting option

456

* @param key the series key

457

* @param autoSort flag to control automatic sorting by X value

458

*/

459

public XYSeries(Comparable key, boolean autoSort);

460

461

/**

462

* Adds a data item to the series

463

* @param x the X value

464

* @param y the Y value

465

*/

466

public void add(double x, double y);

467

468

/**

469

* Adds a data item to the series

470

* @param x the X value

471

* @param y the Y value

472

*/

473

public void add(Number x, Number y);

474

475

/**

476

* Adds a data item with duplicate X value checking

477

* @param x the X value

478

* @param y the Y value

479

* @param notify flag to control change notification

480

*/

481

public void add(double x, double y, boolean notify);

482

483

/**

484

* Updates an existing data item or adds a new one

485

* @param x the X value

486

* @param y the Y value

487

*/

488

public void addOrUpdate(double x, double y);

489

490

/**

491

* Updates an existing data item or adds a new one

492

* @param x the X value

493

* @param y the Y value

494

*/

495

public void addOrUpdate(Number x, Number y);

496

497

/**

498

* Removes a data item

499

* @param x the X value to remove

500

*/

501

public void remove(Number x);

502

503

/**

504

* Removes a data item by index

505

* @param index the item index

506

*/

507

public void remove(int index);

508

509

/**

510

* Removes all data items

511

*/

512

public void clear();

513

514

/**

515

* Returns a data item

516

* @param index the item index

517

* @return the data item

518

*/

519

public XYDataItem getDataItem(int index);

520

521

/**

522

* Returns the number of data items

523

* @return the item count

524

*/

525

public int getItemCount();

526

527

/**

528

* Returns the X value for an item

529

* @param index the item index

530

* @return the X value

531

*/

532

public Number getX(int index);

533

534

/**

535

* Returns the Y value for an item

536

* @param index the item index

537

* @return the Y value

538

*/

539

public Number getY(int index);

540

541

/**

542

* Updates the Y value for an existing X value

543

* @param x the X value

544

* @param y the new Y value

545

*/

546

public void updateByX(Number x, Number y);

547

548

/**

549

* Updates the Y value at a specific index

550

* @param index the item index

551

* @param y the new Y value

552

*/

553

public void updateByIndex(int index, Number y);

554

555

/**

556

* Creates a copy of the series for a range of X values

557

* @param start the start X value

558

* @param end the end X value

559

* @return a new series containing the data in the specified range

560

*/

561

public XYSeries createCopy(int start, int end);

562

563

/**

564

* Converts the series data to arrays

565

* @return an array containing [xArray, yArray]

566

*/

567

public double[][] toArray();

568

}

569

```

570

571

**Usage Example:**

572

573

```java

574

import org.jfree.data.xy.*;

575

576

// Create XY series

577

XYSeries series1 = new XYSeries("Temperature");

578

series1.add(1.0, 20.5);

579

series1.add(2.0, 22.1);

580

series1.add(3.0, 19.8);

581

series1.add(4.0, 25.2);

582

583

XYSeries series2 = new XYSeries("Pressure");

584

series2.add(1.0, 1013.2);

585

series2.add(2.0, 1015.1);

586

series2.add(3.0, 1010.8);

587

series2.add(4.0, 1018.3);

588

589

// Create collection

590

XYSeriesCollection dataset = new XYSeriesCollection();

591

dataset.addSeries(series1);

592

dataset.addSeries(series2);

593

594

// Access data

595

double temp = dataset.getYValue(0, 1); // Temperature at point 1: 22.1

596

int seriesCount = dataset.getSeriesCount(); // 2

597

int itemCount = dataset.getItemCount(0); // 4 items in first series

598

599

// Update data

600

series1.addOrUpdate(5.0, 23.7); // Add new point or update existing

601

series1.updateByX(2.0, 21.5); // Update Y value for X=2.0

602

```

603

604

### Time Series Data

605

606

Specialized datasets for time-based data with support for different time periods and automatic aging.

607

608

```java { .api }

609

/**

610

* Time series data indexed by time periods

611

*/

612

public class TimeSeries implements Cloneable, Serializable {

613

/**

614

* Creates a new time series

615

* @param name the series name

616

*/

617

public TimeSeries(Comparable name);

618

619

/**

620

* Adds a data item to the series

621

* @param period the time period

622

* @param value the value

623

*/

624

public void add(RegularTimePeriod period, Number value);

625

626

/**

627

* Adds a data item to the series

628

* @param period the time period

629

* @param value the value

630

*/

631

public void add(RegularTimePeriod period, double value);

632

633

/**

634

* Adds a data item with notification control

635

* @param period the time period

636

* @param value the value

637

* @param notify flag to control change notification

638

*/

639

public void add(RegularTimePeriod period, Number value, boolean notify);

640

641

/**

642

* Updates an existing data item or adds a new one

643

* @param period the time period

644

* @param value the value

645

*/

646

public void addOrUpdate(RegularTimePeriod period, Number value);

647

648

/**

649

* Updates an existing data item or adds a new one

650

* @param period the time period

651

* @param value the value

652

*/

653

public void addOrUpdate(RegularTimePeriod period, double value);

654

655

/**

656

* Updates an existing data item by index

657

* @param index the item index

658

* @param value the new value

659

*/

660

public void update(int index, Number value);

661

662

/**

663

* Updates an existing data item by time period

664

* @param period the time period

665

* @param value the new value

666

*/

667

public void update(RegularTimePeriod period, Number value);

668

669

/**

670

* Removes a data item

671

* @param period the time period to remove

672

*/

673

public void delete(RegularTimePeriod period);

674

675

/**

676

* Removes a data item by index

677

* @param index the item index

678

*/

679

public void delete(int index);

680

681

/**

682

* Removes a range of data items

683

* @param start the start index (inclusive)

684

* @param end the end index (inclusive)

685

*/

686

public void delete(int start, int end);

687

688

/**

689

* Removes all data items

690

*/

691

public void clear();

692

693

/**

694

* Returns a data item

695

* @param index the item index

696

* @return the data item

697

*/

698

public TimeSeriesDataItem getDataItem(int index);

699

700

/**

701

* Returns a data item by time period

702

* @param period the time period

703

* @return the data item, or null if not found

704

*/

705

public TimeSeriesDataItem getDataItem(RegularTimePeriod period);

706

707

/**

708

* Returns the number of data items

709

* @return the item count

710

*/

711

public int getItemCount();

712

713

/**

714

* Returns the time period for an item

715

* @param index the item index

716

* @return the time period

717

*/

718

public RegularTimePeriod getTimePeriod(int index);

719

720

/**

721

* Returns the value for an item

722

* @param index the item index

723

* @return the value

724

*/

725

public Number getValue(int index);

726

727

/**

728

* Returns the value for a time period

729

* @param period the time period

730

* @return the value, or null if not found

731

*/

732

public Number getValue(RegularTimePeriod period);

733

734

/**

735

* Creates a copy of the series for a time range

736

* @param start the start period

737

* @param end the end period

738

* @return a new series containing data in the specified range

739

*/

740

public TimeSeries createCopy(RegularTimePeriod start, RegularTimePeriod end);

741

742

/**

743

* Creates a copy of the series for an index range

744

* @param start the start index

745

* @param end the end index

746

* @return a new series containing data in the specified range

747

*/

748

public TimeSeries createCopy(int start, int end);

749

750

/**

751

* Removes aged items from the series

752

* @param maxAge maximum age in milliseconds

753

* @param notify flag to control change notification

754

*/

755

public void removeAgedItems(long maxAge, boolean notify);

756

757

/**

758

* Gets the maximum number of items allowed in the series

759

* @return the maximum item count

760

*/

761

public int getMaximumItemCount();

762

763

/**

764

* Sets the maximum number of items allowed in the series

765

* @param maximum the maximum item count

766

*/

767

public void setMaximumItemCount(int maximum);

768

769

/**

770

* Gets the maximum age for items in the series

771

* @return the maximum age in milliseconds

772

*/

773

public long getMaximumItemAge();

774

775

/**

776

* Sets the maximum age for items in the series

777

* @param periods the maximum age in time periods

778

*/

779

public void setMaximumItemAge(long periods);

780

}

781

782

/**

783

* Collection of time series for creating multi-series time-based datasets

784

*/

785

public class TimeSeriesCollection implements XYDataset, IntervalXYDataset {

786

/**

787

* Creates a new empty collection

788

*/

789

public TimeSeriesCollection();

790

791

/**

792

* Creates a collection with a single time series

793

* @param series the initial series

794

*/

795

public TimeSeriesCollection(TimeSeries series);

796

797

/**

798

* Adds a time series to the collection

799

* @param series the series

800

*/

801

public void addSeries(TimeSeries series);

802

803

/**

804

* Removes a time series from the collection

805

* @param series the series

806

*/

807

public void removeSeries(TimeSeries series);

808

809

/**

810

* Removes a time series by index

811

* @param index the series index

812

*/

813

public void removeSeries(int index);

814

815

/**

816

* Removes all time series from the collection

817

*/

818

public void removeAllSeries();

819

820

/**

821

* Returns a time series by index

822

* @param series the series index

823

* @return the time series

824

*/

825

public TimeSeries getSeries(int series);

826

827

/**

828

* Returns a time series by key

829

* @param key the series key

830

* @return the time series, or null if not found

831

*/

832

public TimeSeries getSeries(Comparable key);

833

834

/**

835

* Returns the series index for a given key

836

* @param key the series key

837

* @return the series index, or -1 if not found

838

*/

839

public int indexOf(Comparable key);

840

}

841

```

842

843

**Usage Example:**

844

845

```java

846

import org.jfree.data.time.*;

847

848

// Create time series

849

TimeSeries stockPrice = new TimeSeries("AAPL");

850

stockPrice.add(new Day(1, 1, 2023), 150.0);

851

stockPrice.add(new Day(2, 1, 2023), 152.5);

852

stockPrice.add(new Day(3, 1, 2023), 148.2);

853

854

// Configure automatic aging

855

stockPrice.setMaximumItemCount(100); // Keep last 100 items

856

stockPrice.setMaximumItemAge(365); // Keep items up to 365 days old

857

858

// Update values

859

stockPrice.addOrUpdate(new Day(3, 1, 2023), 149.8); // Update existing

860

stockPrice.addOrUpdate(new Day(4, 1, 2023), 151.3); // Add new

861

862

// Create collection

863

TimeSeriesCollection dataset = new TimeSeriesCollection();

864

dataset.addSeries(stockPrice);

865

866

// Access data

867

Number value = stockPrice.getValue(new Day(2, 1, 2023)); // 152.5

868

int itemCount = stockPrice.getItemCount(); // 4 items

869

870

// Create subset

871

TimeSeries lastWeek = stockPrice.createCopy(

872

new Day(28, 12, 2022), new Day(4, 1, 2023));

873

```

874

875

### Pie Datasets

876

877

Datasets for pie charts representing categorical data as proportions of a whole.

878

879

```java { .api }

880

/**

881

* Dataset for pie charts (extends KeyedValues)

882

*/

883

public interface PieDataset<K> extends KeyedValues<K>, Dataset {

884

// Inherited from KeyedValues<K>:

885

886

/**

887

* Returns the number of items in the dataset

888

* @return the item count

889

*/

890

public int getItemCount();

891

892

/**

893

* Returns a value by key

894

* @param key the key

895

* @return the value (possibly null)

896

*/

897

public Number getValue(K key);

898

899

/**

900

* Returns a value by index

901

* @param item the item index (zero-based)

902

* @return the value (possibly null)

903

*/

904

public Number getValue(int item);

905

906

/**

907

* Returns a key by index

908

* @param item the item index (zero-based)

909

* @return the key

910

*/

911

public K getKey(int item);

912

913

/**

914

* Returns all keys

915

* @return a list of keys

916

*/

917

public List<K> getKeys();

918

919

/**

920

* Returns the index for a given key

921

* @param key the key

922

* @return the index, or -1 if not found

923

*/

924

public int getIndex(K key);

925

}

926

927

/**

928

* Default implementation of PieDataset

929

*/

930

public class DefaultPieDataset<K> implements PieDataset<K> {

931

/**

932

* Creates a new empty pie dataset

933

*/

934

public DefaultPieDataset();

935

936

/**

937

* Sets a value in the dataset

938

* @param key the key

939

* @param value the value

940

*/

941

public void setValue(K key, Number value);

942

943

/**

944

* Sets a value in the dataset

945

* @param key the key

946

* @param value the value

947

*/

948

public void setValue(K key, double value);

949

950

/**

951

* Removes a value from the dataset

952

* @param key the key

953

*/

954

public void remove(K key);

955

956

/**

957

* Removes all values from the dataset

958

*/

959

public void clear();

960

961

/**

962

* Sorts the dataset by keys

963

* @param order the sort order (ASCENDING or DESCENDING)

964

*/

965

public void sortByKeys(SortOrder order);

966

967

/**

968

* Sorts the dataset by values

969

* @param order the sort order (ASCENDING or DESCENDING)

970

*/

971

public void sortByValues(SortOrder order);

972

}

973

```

974

975

**Usage Example:**

976

977

```java

978

import org.jfree.data.general.DefaultPieDataset;

979

980

// Create pie dataset

981

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

982

dataset.setValue("Chrome", 65.2);

983

dataset.setValue("Firefox", 18.7);

984

dataset.setValue("Safari", 9.6);

985

dataset.setValue("Edge", 4.8);

986

dataset.setValue("Other", 1.7);

987

988

// Access data

989

Number chromeShare = dataset.getValue("Chrome"); // 65.2

990

int categories = dataset.getItemCount(); // 5

991

String topBrowser = dataset.getKey(0); // First key

992

993

// Sort by values (descending)

994

dataset.sortByValues(SortOrder.DESCENDING);

995

996

// Remove small categories

997

dataset.remove("Other");

998

999

// Clear all data

1000

dataset.clear();

1001

```

1002

1003

### Specialized Datasets

1004

1005

Datasets for specialized chart types and advanced use cases.

1006

1007

```java { .api }

1008

// Financial data for candlestick and high-low charts

1009

public interface OHLCDataset extends XYDataset {

1010

public Number getHigh(int series, int item);

1011

public double getHighValue(int series, int item);

1012

public Number getLow(int series, int item);

1013

public double getLowValue(int series, int item);

1014

public Number getOpen(int series, int item);

1015

public double getOpenValue(int series, int item);

1016

public Number getClose(int series, int item);

1017

public double getCloseValue(int series, int item);

1018

public Number getVolume(int series, int item);

1019

public double getVolumeValue(int series, int item);

1020

}

1021

1022

// Statistical data for box and whisker plots

1023

public interface BoxAndWhiskerCategoryDataset extends CategoryDataset {

1024

public Number getMean(int row, int column);

1025

public Number getMean(Comparable rowKey, Comparable columnKey);

1026

public Number getMedian(int row, int column);

1027

public Number getMedian(Comparable rowKey, Comparable columnKey);

1028

public Number getQ1(int row, int column);

1029

public Number getQ1(Comparable rowKey, Comparable columnKey);

1030

public Number getQ3(int row, int column);

1031

public Number getQ3(Comparable rowKey, Comparable columnKey);

1032

public Number getMinRegularValue(int row, int column);

1033

public Number getMinRegularValue(Comparable rowKey, Comparable columnKey);

1034

public Number getMaxRegularValue(int row, int column);

1035

public Number getMaxRegularValue(Comparable rowKey, Comparable columnKey);

1036

public List getOutliers(int row, int column);

1037

public List getOutliers(Comparable rowKey, Comparable columnKey);

1038

}

1039

1040

// 3D datasets for bubble charts

1041

public class DefaultXYZDataset implements XYZDataset {

1042

public DefaultXYZDataset();

1043

public void addSeries(Comparable seriesKey, double[][] data);

1044

public void removeSeries(Comparable seriesKey);

1045

public void removeAllSeries();

1046

}

1047

1048

// Gantt chart datasets

1049

public interface GanttCategoryDataset extends IntervalCategoryDataset {

1050

public Number getPercentComplete(int row, int column);

1051

public Number getPercentComplete(Comparable rowKey, Comparable columnKey);

1052

public int getSubIntervalCount(int row, int column);

1053

public int getSubIntervalCount(Comparable rowKey, Comparable columnKey);

1054

public Number getStartValue(int row, int column, int subinterval);

1055

public Number getEndValue(int row, int column, int subinterval);

1056

public Number getPercentComplete(int row, int column, int subinterval);

1057

}

1058

```