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

export-display.mddocs/

0

# Export and Display

1

2

Utilities for displaying charts in GUI applications and exporting to various image formats. JFreeChart provides comprehensive support for both interactive display in desktop applications and programmatic image generation for web applications and reports.

3

4

## Capabilities

5

6

### Swing Display Components

7

8

Components for displaying interactive charts in Swing applications with zoom, pan, and menu capabilities.

9

10

```java { .api }

11

/**

12

* Swing panel for displaying charts with interactive features

13

*/

14

public class ChartPanel extends JPanel implements ChartChangeListener, ChartProgressListener, ActionListener, MouseListener, MouseMotionListener, OverlayChangeListener, Printable {

15

16

/**

17

* Creates a chart panel with default settings

18

* @param chart the chart to display

19

*/

20

public ChartPanel(JFreeChart chart);

21

22

/**

23

* Creates a chart panel with buffer control

24

* @param chart the chart to display

25

* @param useBuffer flag to control off-screen buffering

26

*/

27

public ChartPanel(JFreeChart chart, boolean useBuffer);

28

29

/**

30

* Creates a chart panel with full customization

31

* @param chart the chart to display

32

* @param width preferred width

33

* @param height preferred height

34

* @param minimumDrawWidth minimum drawing width

35

* @param minimumDrawHeight minimum drawing height

36

* @param maximumDrawWidth maximum drawing width

37

* @param maximumDrawHeight maximum drawing height

38

* @param useBuffer flag to control off-screen buffering

39

* @param properties flag to show properties menu item

40

* @param copy flag to show copy menu item

41

* @param save flag to show save menu item

42

* @param print flag to show print menu item

43

* @param zoom flag to enable zoom functionality

44

* @param tooltips flag to enable tooltips

45

*/

46

public ChartPanel(JFreeChart chart, int width, int height, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean properties, boolean copy, boolean save, boolean print, boolean zoom, boolean tooltips);

47

48

// Chart management

49

public JFreeChart getChart();

50

public void setChart(JFreeChart chart);

51

52

// Size control

53

public int getMinimumDrawWidth();

54

public void setMinimumDrawWidth(int width);

55

public int getMaximumDrawWidth();

56

public void setMaximumDrawWidth(int width);

57

public int getMinimumDrawHeight();

58

public void setMinimumDrawHeight(int height);

59

public int getMaximumDrawHeight();

60

public void setMaximumDrawHeight(int height);

61

public double getScaleX();

62

public double getScaleY();

63

64

// Buffering

65

public boolean getRefreshBuffer();

66

public void setRefreshBuffer(boolean flag);

67

68

// Zooming

69

public boolean isDomainZoomable();

70

public void setDomainZoomable(boolean zoomable);

71

public boolean isRangeZoomable();

72

public void setRangeZoomable(boolean zoomable);

73

public void restoreAutoBounds();

74

public void restoreAutoRangeBounds();

75

public void restoreAutoDomainBounds();

76

public void zoomInBoth(double x, double y);

77

public void zoomInDomain(double x, double y);

78

public void zoomInRange(double x, double y);

79

public void zoomOutBoth(double x, double y);

80

public void zoomOutDomain(double x, double y);

81

public void zoomOutRange(double x, double y);

82

public void zoom(Rectangle2D selection);

83

public Point2D getZoomPoint();

84

public void setZoomPoint(Point2D zoomPoint);

85

public boolean getZoomAroundAnchor();

86

public void setZoomAroundAnchor(boolean zoomAroundAnchor);

87

public double getZoomInFactor();

88

public void setZoomInFactor(double factor);

89

public double getZoomOutFactor();

90

public void setZoomOutFactor(double factor);

91

public int getZoomTriggerDistance();

92

public void setZoomTriggerDistance(int distance);

93

94

// Popup menu

95

public JPopupMenu getPopupMenu();

96

public void setPopupMenu(JPopupMenu popup);

97

public ChartPanelPopupMenuOrder getPopupMenuOrder();

98

public void setPopupMenuOrder(ChartPanelPopupMenuOrder order);

99

100

// Tooltips

101

public boolean isDisplayToolTips();

102

public void setDisplayToolTips(boolean flag);

103

public String getToolTipText(MouseEvent e);

104

public Point translateJava2DToScreen(Point2D java2DPoint);

105

public Point2D translateScreenToJava2D(Point screenPoint);

106

public Rectangle2D scale(Rectangle2D rect);

107

108

// Rendering info

109

public ChartRenderingInfo getChartRenderingInfo();

110

111

// Mouse event handling

112

public void addChartMouseListener(ChartMouseListener listener);

113

public void removeChartMouseListener(ChartMouseListener listener);

114

115

// Overlays

116

public void addOverlay(Overlay overlay);

117

public void removeOverlay(Overlay overlay);

118

119

// Editor

120

public void doEditChartProperties();

121

122

// File operations

123

public void doSaveAs() throws IOException;

124

public void doCopy();

125

public void doPrint();

126

127

// Constants

128

public static final boolean DEFAULT_BUFFER_USED = true;

129

public static final int DEFAULT_WIDTH = 680;

130

public static final int DEFAULT_HEIGHT = 420;

131

public static final int DEFAULT_MINIMUM_DRAW_WIDTH = 300;

132

public static final int DEFAULT_MINIMUM_DRAW_HEIGHT = 200;

133

public static final int DEFAULT_MAXIMUM_DRAW_WIDTH = 1024;

134

public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT = 768;

135

public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE = 10;

136

}

137

138

/**

139

* Specialized chart panel for polar plots

140

*/

141

public class PolarChartPanel extends ChartPanel {

142

/**

143

* Creates a polar chart panel

144

* @param chart the polar chart to display

145

*/

146

public PolarChartPanel(JFreeChart chart);

147

148

public boolean isRotateEnabled();

149

public void setRotateEnabled(boolean enabled);

150

public double getAngle();

151

public void setAngle(double angle);

152

}

153

154

/**

155

* Chart panel optimized for background rendering

156

*/

157

public class OfflineRenderingChartPanel extends ChartPanel {

158

/**

159

* Creates an offline rendering chart panel

160

* @param chart the chart to display

161

*/

162

public OfflineRenderingChartPanel(JFreeChart chart);

163

164

public boolean isRenderingOffscreen();

165

public void setRenderingOffscreen(boolean flag);

166

}

167

```

168

169

**Usage Example:**

170

171

```java

172

import org.jfree.chart.*;

173

import javax.swing.*;

174

175

// Create chart panel with default settings

176

JFreeChart chart = ChartFactory.createLineChart(

177

"Temperature Data", "Time", "Temperature (°C)", dataset);

178

179

ChartPanel chartPanel = new ChartPanel(chart);

180

181

// Customize chart panel

182

chartPanel.setPreferredSize(new Dimension(800, 600));

183

chartPanel.setMinimumDrawWidth(400);

184

chartPanel.setMaximumDrawWidth(1200);

185

chartPanel.setMinimumDrawHeight(300);

186

chartPanel.setMaximumDrawHeight(800);

187

188

// Enable interactive features

189

chartPanel.setDomainZoomable(true);

190

chartPanel.setRangeZoomable(true);

191

chartPanel.setDisplayToolTips(true);

192

193

// Configure zoom behavior

194

chartPanel.setZoomAroundAnchor(true);

195

chartPanel.setZoomInFactor(0.9);

196

chartPanel.setZoomOutFactor(1.1);

197

198

// Add to Swing application

199

JFrame frame = new JFrame("Chart Application");

200

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

201

frame.add(chartPanel);

202

frame.pack();

203

frame.setVisible(true);

204

205

// Add mouse listener for chart events

206

chartPanel.addChartMouseListener(new ChartMouseListener() {

207

public void chartMouseClicked(ChartMouseEvent event) {

208

ChartEntity entity = event.getEntity();

209

if (entity != null) {

210

System.out.println("Clicked: " + entity.toString());

211

}

212

}

213

214

public void chartMouseMoved(ChartMouseEvent event) {

215

// Handle mouse movement

216

}

217

});

218

```

219

220

### Image Export Utilities

221

222

Static utility methods for exporting charts to various image formats.

223

224

```java { .api }

225

/**

226

* Utility class for chart operations and image export

227

*/

228

public abstract class ChartUtils {

229

230

// Theme management

231

public static void applyCurrentTheme(JFreeChart chart);

232

233

// PNG export

234

public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height) throws IOException;

235

public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException;

236

public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height, boolean encodeAlpha, int compression) throws IOException;

237

public static void writeChartAsPNG(OutputStream out, JFreeChart chart, int width, int height, ChartRenderingInfo info, boolean encodeAlpha, int compression) throws IOException;

238

239

public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height) throws IOException;

240

public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException;

241

public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info, boolean encodeAlpha, int compression) throws IOException;

242

243

public static void writeScaledChartAsPNG(OutputStream out, JFreeChart chart, int width, int height, int widthScaleFactor, int heightScaleFactor) throws IOException;

244

245

// JPEG export

246

public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, int width, int height) throws IOException;

247

public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException;

248

public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, int width, int height, float quality) throws IOException;

249

public static void writeChartAsJPEG(OutputStream out, JFreeChart chart, int width, int height, ChartRenderingInfo info, float quality) throws IOException;

250

251

public static void saveChartAsJPEG(File file, JFreeChart chart, int width, int height) throws IOException;

252

public static void saveChartAsJPEG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info) throws IOException;

253

public static void saveChartAsJPEG(File file, JFreeChart chart, int width, int height, float quality) throws IOException;

254

public static void saveChartAsJPEG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info, float quality) throws IOException;

255

256

// Image map generation for web applications

257

public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info) throws IOException;

258

public static void writeImageMap(PrintWriter writer, String name, ChartRenderingInfo info, ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, URLTagFragmentGenerator urlTagFragmentGenerator) throws IOException;

259

260

public static String getImageMap(String name, ChartRenderingInfo info);

261

public static String getImageMap(String name, ChartRenderingInfo info, ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, URLTagFragmentGenerator urlTagFragmentGenerator);

262

}

263

264

/**

265

* Rendering information collected during chart drawing

266

*/

267

public class ChartRenderingInfo implements Cloneable, Serializable {

268

/**

269

* Creates new rendering info

270

*/

271

public ChartRenderingInfo();

272

273

/**

274

* Creates rendering info with entity collection

275

* @param entities the entity collection

276

*/

277

public ChartRenderingInfo(EntityCollection entities);

278

279

public void clear();

280

public PlotRenderingInfo getPlotInfo();

281

public void setPlotInfo(PlotRenderingInfo plotInfo);

282

public Rectangle2D getChartArea();

283

public void setChartArea(Rectangle2D area);

284

public EntityCollection getEntityCollection();

285

public void setEntityCollection(EntityCollection entities);

286

}

287

288

/**

289

* Entity collection for interactive chart areas

290

*/

291

public interface EntityCollection {

292

public void add(ChartEntity entity);

293

public void addAll(EntityCollection collection);

294

public void clear();

295

public ChartEntity getEntity(double x, double y);

296

public ChartEntity getEntity(int index);

297

public int getEntityCount();

298

public Collection getEntities();

299

public Iterator iterator();

300

}

301

302

/**

303

* Standard entity collection implementation

304

*/

305

public class StandardEntityCollection implements EntityCollection {

306

public StandardEntityCollection();

307

308

public void add(ChartEntity entity);

309

public void addAll(EntityCollection collection);

310

public void clear();

311

public ChartEntity getEntity(double x, double y);

312

public ChartEntity getEntity(int index);

313

public int getEntityCount();

314

public Collection getEntities();

315

public Iterator iterator();

316

}

317

```

318

319

**Usage Example:**

320

321

```java

322

import org.jfree.chart.ChartUtils;

323

import java.io.*;

324

325

// Export chart as PNG

326

try {

327

ChartUtils.saveChartAsPNG(

328

new File("chart.png"),

329

chart,

330

800, 600

331

);

332

} catch (IOException e) {

333

e.printStackTrace();

334

}

335

336

// Export with rendering info for image maps

337

ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());

338

try {

339

// Save image with entity information

340

ChartUtils.saveChartAsPNG(

341

new File("interactive_chart.png"),

342

chart,

343

800, 600,

344

info

345

);

346

347

// Generate HTML image map

348

String imageMap = ChartUtils.getImageMap("chart", info);

349

350

// Write complete HTML

351

PrintWriter htmlWriter = new PrintWriter(new FileWriter("chart.html"));

352

htmlWriter.println("<html><body>");

353

htmlWriter.println("<img src='interactive_chart.png' usemap='#chart' />");

354

htmlWriter.println(imageMap);

355

htmlWriter.println("</body></html>");

356

htmlWriter.close();

357

358

} catch (IOException e) {

359

e.printStackTrace();

360

}

361

362

// Export as JPEG with quality control

363

try {

364

ChartUtils.saveChartAsJPEG(

365

new File("chart.jpg"),

366

chart,

367

800, 600,

368

0.95f // 95% quality

369

);

370

} catch (IOException e) {

371

e.printStackTrace();

372

}

373

374

// Stream export for web applications

375

try (OutputStream out = response.getOutputStream()) {

376

response.setContentType("image/png");

377

ChartUtils.writeChartAsPNG(out, chart, 600, 400);

378

} catch (IOException e) {

379

e.printStackTrace();

380

}

381

```

382

383

### Chart Event Handling

384

385

Event interfaces and classes for handling chart changes and user interactions.

386

387

```java { .api }

388

/**

389

* Listener interface for chart change events

390

*/

391

public interface ChartChangeListener extends EventListener {

392

/**

393

* Called when a chart is changed

394

* @param event details about the change event

395

*/

396

public void chartChanged(ChartChangeEvent event);

397

}

398

399

/**

400

* Chart change event information

401

*/

402

public class ChartChangeEvent extends EventObject {

403

/**

404

* Creates a chart change event

405

* @param source the chart that changed

406

*/

407

public ChartChangeEvent(Object source);

408

409

/**

410

* Creates a chart change event with chart reference

411

* @param source the object that changed

412

* @param chart the chart that was affected

413

*/

414

public ChartChangeEvent(Object source, JFreeChart chart);

415

416

public JFreeChart getChart();

417

public ChartChangeEventType getType();

418

}

419

420

/**

421

* Listener interface for chart progress events

422

*/

423

public interface ChartProgressListener extends EventListener {

424

/**

425

* Called when chart drawing progresses

426

* @param event details about the progress event

427

*/

428

public void chartProgress(ChartProgressEvent event);

429

}

430

431

/**

432

* Chart progress event information

433

*/

434

public class ChartProgressEvent extends EventObject {

435

public static final int DRAWING_STARTED = 1;

436

public static final int DRAWING_FINISHED = 2;

437

438

/**

439

* Creates a chart progress event

440

* @param source the chart being drawn

441

* @param chart the chart

442

* @param type the event type

443

* @param percent the percentage complete

444

*/

445

public ChartProgressEvent(Object source, JFreeChart chart, int type, int percent);

446

447

public JFreeChart getChart();

448

public int getType();

449

public int getPercent();

450

}

451

452

/**

453

* Mouse event listener for chart interactions

454

*/

455

public interface ChartMouseListener extends EventListener {

456

/**

457

* Called when the mouse is clicked on a chart

458

* @param event details about the mouse event

459

*/

460

public void chartMouseClicked(ChartMouseEvent event);

461

462

/**

463

* Called when the mouse moves over a chart

464

* @param event details about the mouse event

465

*/

466

public void chartMouseMoved(ChartMouseEvent event);

467

}

468

469

/**

470

* Mouse event information for charts

471

*/

472

public class ChartMouseEvent extends EventObject {

473

/**

474

* Creates a chart mouse event

475

* @param chart the chart

476

* @param trigger the mouse event that triggered this

477

* @param entity the chart entity under the mouse (may be null)

478

*/

479

public ChartMouseEvent(JFreeChart chart, MouseEvent trigger, ChartEntity entity);

480

481

public JFreeChart getChart();

482

public MouseEvent getTrigger();

483

public ChartEntity getEntity();

484

}

485

486

/**

487

* Base class for chart entities (clickable areas)

488

*/

489

public abstract class ChartEntity implements Cloneable, Serializable {

490

/**

491

* Creates a chart entity

492

* @param area the area occupied by the entity

493

*/

494

public ChartEntity(Shape area);

495

496

/**

497

* Creates a chart entity with tooltip

498

* @param area the area occupied by the entity

499

* @param toolTipText the tooltip text

500

*/

501

public ChartEntity(Shape area, String toolTipText);

502

503

/**

504

* Creates a chart entity with tooltip and URL

505

* @param area the area occupied by the entity

506

* @param toolTipText the tooltip text

507

* @param urlText the URL text

508

*/

509

public ChartEntity(Shape area, String toolTipText, String urlText);

510

511

public Shape getArea();

512

public void setArea(Shape area);

513

public String getToolTipText();

514

public void setToolTipText(String text);

515

public String getURLText();

516

public void setURLText(String text);

517

public String getImageMapAreaTag(ToolTipTagFragmentGenerator toolTipTagFragmentGenerator, URLTagFragmentGenerator urlTagFragmentGenerator);

518

}

519

520

/**

521

* Entity representing a data item

522

*/

523

public class CategoryItemEntity extends ChartEntity {

524

public CategoryItemEntity(Shape area, String toolTipText, String urlText, CategoryDataset dataset, Comparable rowKey, Comparable columnKey);

525

526

public CategoryDataset getDataset();

527

public Comparable getRowKey();

528

public Comparable getColumnKey();

529

}

530

531

/**

532

* Entity representing an XY data item

533

*/

534

public class XYItemEntity extends ChartEntity {

535

public XYItemEntity(Shape area, String toolTipText, String urlText, XYDataset dataset, int series, int item);

536

537

public XYDataset getDataset();

538

public int getSeriesIndex();

539

public int getItem();

540

}

541

542

/**

543

* Entity representing a pie section

544

*/

545

public class PieSectionEntity extends ChartEntity {

546

public PieSectionEntity(Shape area, String toolTipText, String urlText, PieDataset dataset, Comparable sectionKey);

547

548

public PieDataset getDataset();

549

public Comparable getSectionKey();

550

}

551

```

552

553

**Usage Example:**

554

555

```java

556

// Add change listener to chart

557

chart.addChangeListener(new ChartChangeListener() {

558

public void chartChanged(ChartChangeEvent event) {

559

System.out.println("Chart changed: " + event.getChart().getTitle().getText());

560

// Update dependent components

561

updateChartSummary();

562

}

563

});

564

565

// Add progress listener for long-running operations

566

chart.addProgressListener(new ChartProgressListener() {

567

public void chartProgress(ChartProgressEvent event) {

568

if (event.getType() == ChartProgressEvent.DRAWING_STARTED) {

569

progressBar.setVisible(true);

570

} else if (event.getType() == ChartProgressEvent.DRAWING_FINISHED) {

571

progressBar.setVisible(false);

572

}

573

progressBar.setValue(event.getPercent());

574

}

575

});

576

577

// Handle mouse interactions with chart entities

578

chartPanel.addChartMouseListener(new ChartMouseListener() {

579

public void chartMouseClicked(ChartMouseEvent event) {

580

ChartEntity entity = event.getEntity();

581

if (entity instanceof CategoryItemEntity) {

582

CategoryItemEntity item = (CategoryItemEntity) entity;

583

System.out.println("Clicked on: " + item.getRowKey() + ", " + item.getColumnKey());

584

// Show detail dialog or update display

585

showItemDetails(item);

586

} else if (entity instanceof XYItemEntity) {

587

XYItemEntity item = (XYItemEntity) entity;

588

System.out.println("Clicked on series " + item.getSeriesIndex() + ", item " + item.getItem());

589

}

590

}

591

592

public void chartMouseMoved(ChartMouseEvent event) {

593

// Update status bar with entity information

594

ChartEntity entity = event.getEntity();

595

if (entity != null) {

596

statusLabel.setText(entity.getToolTipText());

597

} else {

598

statusLabel.setText("");

599

}

600

}

601

});

602

```

603

604

### Advanced Display Features

605

606

Advanced display capabilities including overlays, printing, and custom rendering.

607

608

```java { .api }

609

// Overlay support for additional graphics

610

public interface Overlay {

611

public void paintOverlay(Graphics2D g2, ChartPanel chartPanel);

612

public void addChangeListener(OverlayChangeListener listener);

613

public void removeChangeListener(OverlayChangeListener listener);

614

}

615

616

public class CrosshairOverlay implements Overlay {

617

public CrosshairOverlay();

618

public void addDomainCrosshair(Crosshair crosshair);

619

public void removeDomainCrosshair(Crosshair crosshair);

620

public void clearDomainCrosshairs();

621

public void addRangeCrosshair(Crosshair crosshair);

622

public void removeRangeCrosshair(Crosshair crosshair);

623

public void clearRangeCrosshairs();

624

}

625

626

public class Crosshair implements Cloneable, PublicCloneable, Serializable {

627

public Crosshair();

628

public Crosshair(double value);

629

public Crosshair(double value, Paint paint, Stroke stroke);

630

631

public boolean isVisible();

632

public void setVisible(boolean visible);

633

public double getValue();

634

public void setValue(double value);

635

public Paint getPaint();

636

public void setPaint(Paint paint);

637

public Stroke getStroke();

638

public void setStroke(Stroke stroke);

639

public boolean isLabelVisible();

640

public void setLabelVisible(boolean visible);

641

public String getLabel();

642

public void setLabel(String label);

643

}

644

645

// Printing support

646

public interface Printable {

647

public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException;

648

}

649

650

// Custom mouse wheel handling

651

public class MouseWheelHandler implements MouseWheelListener {

652

public MouseWheelHandler(ChartPanel chartPanel);

653

public double getZoomFactor();

654

public void setZoomFactor(double zoomFactor);

655

public void mouseWheelMoved(MouseWheelEvent e);

656

}

657

658

// Chart transferable for clipboard operations

659

public class ChartTransferable implements Transferable {

660

public ChartTransferable(JFreeChart chart, int width, int height);

661

public ChartTransferable(JFreeChart chart, int width, int height, boolean drawBorder);

662

663

public DataFlavor[] getTransferDataFlavors();

664

public boolean isDataFlavorSupported(DataFlavor flavor);

665

public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException;

666

}

667

```

668

669

**Usage Example:**

670

671

```java

672

// Add crosshair overlay

673

CrosshairOverlay overlay = new CrosshairOverlay();

674

675

// Create domain crosshair

676

Crosshair domainCrosshair = new Crosshair(0.0, Color.RED, new BasicStroke(1.0f));

677

domainCrosshair.setLabelVisible(true);

678

domainCrosshair.setLabel("Current Time");

679

overlay.addDomainCrosshair(domainCrosshair);

680

681

// Create range crosshair

682

Crosshair rangeCrosshair = new Crosshair(100.0, Color.BLUE, new BasicStroke(1.0f));

683

rangeCrosshair.setLabelVisible(true);

684

rangeCrosshair.setLabel("Target Value");

685

overlay.addRangeCrosshair(rangeCrosshair);

686

687

// Add overlay to chart panel

688

chartPanel.addOverlay(overlay);

689

690

// Enable mouse wheel zooming

691

MouseWheelHandler wheelHandler = new MouseWheelHandler(chartPanel);

692

wheelHandler.setZoomFactor(0.1);

693

chartPanel.addMouseWheelListener(wheelHandler);

694

695

// Configure for printing

696

chartPanel.print(graphics, pageFormat, 0);

697

698

// Copy chart to clipboard

699

Toolkit toolkit = Toolkit.getDefaultToolkit();

700

Clipboard clipboard = toolkit.getSystemClipboard();

701

ChartTransferable transferable = new ChartTransferable(chart, 800, 600);

702

clipboard.setContents(transferable, null);

703

```