Formatage du graphique

Réglage de l’apparence du graphique

Dans les Types de graphique, nous avons brièvement présenté les types de graphiques et d’objets de graphique offerts par Aspose.Cells.

Dans cet article, nous discutons de la personnalisation de l’apparence des graphiques en définissant un certain nombre de propriétés différentes :

Définition de la zone du graphique

Il existe différents types de zones dans un graphique et Aspose.Cells offre la flexibilité de modifier l’apparence de chaque zone. Les développeurs peuvent appliquer différents paramètres de formatage sur une zone en modifiant sa couleur avant-plan, sa couleur d’arrière-plan et son format de remplissage, etc.

Dans l’exemple ci-dessous, nous avons appliqué différents paramètres de mise en forme sur différents types de zones d’un graphique. Ces zones comprennent :

Après l’exécution du code d’exemple, un histogramme à colonnes sera ajouté à la feuille de calcul comme indiqué ci-dessous :

Un histogramme à colonnes avec des zones remplies

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SettingChartArea.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
WorksheetCollection worksheets = workbook.getWorksheets();
// Obtaining the reference of the newly added worksheet by passing its
// sheet index
Worksheet worksheet = worksheets.get(0);
Cells cells = worksheet.getCells();
// Adding a sample value to "A1" cell
cells.get("A1").setValue(50);
// Adding a sample value to "A2" cell
cells.get("A2").setValue(100);
// Adding a sample value to "A3" cell
cells.get("A3").setValue(150);
// Adding a sample value to "B1" cell
cells.get("B1").setValue(60);
// Adding a sample value to "B2" cell
cells.get("B2").setValue(32);
// Adding a sample value to "B3" cell
cells.get("B3").setValue(50);
// Adding a chart to the worksheet
ChartCollection charts = worksheet.getCharts();
// Accessing the instance of the newly added chart
int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 7);
Chart chart = charts.get(chartIndex);
// Adding NSeries (chart data source) to the chart ranging from "A1"
// cell
SeriesCollection nSeries = chart.getNSeries();
nSeries.add("A1:B3", true);
// Setting the foreground color of the plot area
ChartFrame plotArea = chart.getPlotArea();
Area area = plotArea.getArea();
area.setForegroundColor(Color.getBlue());
// Setting the foreground color of the chart area
ChartArea chartArea = chart.getChartArea();
area = chartArea.getArea();
area.setForegroundColor(Color.getYellow());
// Setting the foreground color of the 1st NSeries area
Series aSeries = nSeries.get(0);
area = aSeries.getArea();
area.setForegroundColor(Color.getRed());
// Setting the foreground color of the area of the 1st NSeries point
ChartPointCollection chartPoints = aSeries.getPoints();
ChartPoint point = chartPoints.get(0);
point.getArea().setForegroundColor(Color.getCyan());
// Save the Excel file
workbook.save(dataDir + "SettingChartArea_out.xls");
// Print message
System.out.println("ChartArea is settled successfully.");

Définition des lignes du graphique

Les développeurs peuvent également appliquer différents types de styles sur les lignes ou les repères de données du SeriesCollection comme indiqué ci-dessous dans l’exemple. L’exécution du code d’exemple ajoute un histogramme à colonnes à la feuille de calcul comme indiqué ci-dessous :

Histogramme à colonnes après application des styles de ligne

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SettingChartLines.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
WorksheetCollection worksheets = workbook.getWorksheets();
// Obtaining the reference of the newly added worksheet by passing its
// sheet index
Worksheet worksheet = worksheets.get(0);
Cells cells = worksheet.getCells();
// Adding a chart to the worksheet
ChartCollection charts = worksheet.getCharts();
Chart chart = charts.get(0);
// Adding NSeries (chart data source) to the chart ranging from "A1"
// cell
SeriesCollection nSeries = chart.getNSeries();
nSeries.add("A1:B3", true);
Series aSeries = nSeries.get(0);
Line line = aSeries.getSeriesLines();
line.setStyle(LineType.DOT);
// Applying a triangular marker style on the data markers of an NSeries
aSeries.getMarker().setMarkerStyle(ChartMarkerType.TRIANGLE);
// Setting the weight of all lines in an NSeries to medium
aSeries = nSeries.get(1);
line = aSeries.getSeriesLines();
line.setWeight(WeightType.MEDIUM_LINE);
// Save the Excel file
workbook.save(dataDir + "SettingChartLines_out.xls");
// Print message
System.out.println("ChartArea is settled successfully.");

Application des thèmes Microsoft Excel 2007/2010 aux graphiques

Les développeurs peuvent appliquer différents thèmes et couleurs Microsoft Excel au SeriesCollection ou à d’autres objets graphiques comme indiqué dans l’exemple ci-dessous.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ApplyingThemes.class) + "charts/";
// Instantiate the workbook to open the file that contains a chart
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Get the first worksheet
Worksheet worksheet = workbook.getWorksheets().get(0);
// Get the first chart in the sheet
Chart chart = worksheet.getCharts().get(0);
// Specify the FilFormat's type to Solid Fill of the first series
chart.getNSeries().get(0).getArea().getFillFormat().setFillType(FillType.SOLID);
// Get the CellsColor of SolidFill
CellsColor cc = chart.getNSeries().get(0).getArea().getFillFormat().getSolidFill().getCellsColor();
// Create a theme in Accent style
cc.setThemeColor(new ThemeColor(ThemeColorType.ACCENT_6, 0.6));
// Apply the them to the series
chart.getNSeries().get(0).getArea().getFillFormat().getSolidFill().setCellsColor(cc);
// Save the Excel file
workbook.save(dataDir + "AThemes_out.xlsx");

Configuration des titres des graphiques ou des axes

Vous pouvez utiliser Microsoft Excel pour définir les titres d’un graphique et de ses axes dans un environnement WYSIWYG comme indiqué ci-dessous.

Définition des titres d’un graphique et de ses axes à l’aide de Microsoft Excel

todo:image_alt_text

Aspose.Cells permet également aux développeurs de définir les titres d’un graphique et de ses axes à l’exécution. Tous les graphiques et leurs axes contiennent une méthode Title.setText qui peut être utilisée pour définir leurs titres comme indiqué dans l’exemple ci-dessous. Après l’exécution du code d’exemple, un histogramme à colonnes sera ajouté à la feuille de calcul comme indiqué ci-dessous :

Histogramme à colonnes après la définition des titres

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(SettingTitlesAxes.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
WorksheetCollection worksheets = workbook.getWorksheets();
// Obtaining the reference of the newly added worksheet by passing its
// sheet index
Worksheet worksheet = worksheets.get(0);
Cells cells = worksheet.getCells();
// Adding a chart to the worksheet
ChartCollection charts = worksheet.getCharts();
// Accessing the instance of the newly added chart
int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 7);
Chart chart = charts.get(chartIndex);
// Setting the title of a chart
Title title = chart.getTitle();
title.setText("ASPOSE");
// Setting the font color of the chart title to blue
Font font = title.getFont();
font.setColor(Color.getBlue());
// Setting the title of category axis of the chart
Axis categoryAxis = chart.getCategoryAxis();
title = categoryAxis.getTitle();
title.setText("Category");
// Setting the title of value axis of the chart
Axis valueAxis = chart.getValueAxis();
title = valueAxis.getTitle();
title.setText("Value");
// Adding NSeries (chart data source) to the chart ranging from "A1"
// cell
SeriesCollection nSeries = chart.getNSeries();
nSeries.add("A1:B3", true);
// Setting the foreground color of the plot area
ChartFrame plotArea = chart.getPlotArea();
Area area = plotArea.getArea();
area.setForegroundColor(Color.getBlue());
// Setting the foreground color of the chart area
ChartArea chartArea = chart.getChartArea();
area = chartArea.getArea();
area.setForegroundColor(Color.getYellow());
// Setting the foreground color of the 1st NSeries area
Series aSeries = nSeries.get(0);
area = aSeries.getArea();
area.setForegroundColor(Color.getRed());
// Setting the foreground color of the area of the 1st NSeries point
ChartPointCollection chartPoints = aSeries.getPoints();
ChartPoint point = chartPoints.get(0);
point.getArea().setForegroundColor(Color.getCyan());
// Save the Excel file
workbook.save(dataDir + "SettingTitlesAxes_out.xls");
// Print message
System.out.println("Chart Title is changed successfully.");

Définition des principales lignes de la grille

Masquer les grandes lignes de la grille

Les développeurs peuvent contrôler la visibilité des grandes lignes de la grille en utilisant la méthode setVisible de l’objet Line. Après avoir masqué les grandes lignes de la grille, un graphique à colonnes ajouté à la feuille de calcul présente l’apparence suivante :

Un graphique à colonnes avec des grandes lignes de grille masquées

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Hiding the major gridlines of value axis
Axis valueAxis = chart.getValueAxis();
Line majorGridLines = valueAxis.getMajorGridLines();
majorGridLines.setVisible(false);

Changer les paramètres des grandes lignes de la grille

Les développeurs peuvent non seulement contrôler la visibilité des grandes lignes de la grille, mais aussi d’autres propriétés telles que sa couleur, etc. Après avoir défini la couleur des grandes lignes de la grille, un graphique à colonnes ajouté à la feuille de calcul aura l’apparence suivante :

Graphique à colonnes avec des grandes lignes de grille colorées

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Setting the color of major gridlines of value axis to silver
Axis categoryAxis = chart.getCategoryAxis();
categoryAxis.getMajorGridLines().setColor(Color.getSilver());

Définition des bordures pour les parois arrière et latérales

Depuis la sortie de Microsoft Excel 2007, les parois d’un graphique 3D ont été divisées en deux parties : paroi latérale et paroi arrière, donc nous devons utiliser deux objets Walls pour les représenter séparément et vous pouvez y accéder en utilisant Chart.getBackWall() et Chart.getSideWall().

L’exemple ci-dessous montre comment définir la bordure de la paroi latérale en utilisant différentes attributs.

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// Get the side wall border line
Line sideLine = chart.getSideWall().getBorder();
// Make it visible
sideLine.setVisible(true);
// Set the solid line
sideLine.setStyle(LineType.SOLID);
// Set the line width
sideLine.setWeight(10);
// Set the color
sideLine.setColor(Color.getBlack());

Modifier la position et la taille du graphique

Parfois, vous souhaitez modifier la position ou la taille du graphique nouvellement ajouté ou existant à l’intérieur de la feuille de calcul. Aspose.Cells fournit la propriété Chart.getChartObject() pour y parvenir. Vous pouvez utiliser ses sous-propriétés pour redimensionner le graphique avec une nouvelle hauteur et largeur ou le repositionner avec de nouvelles coordonnées X et Y.

Modifier la position et la taille du graphique

Pour changer la position (coordonnées X, Y) et la taille (hauteur, largeur) du graphique, utilisez ces propriétés :

  1. Chart.getChartObject().get/setWidth()
  2. Chart.getChartObject().get/setHeight()
  3. Chart.getChartObject().get/setX()
  4. Chart.getChartObject().get/setY()

L’exemple suivant explique l’utilisation des propriétés ci-dessus. Il charge le classeur existant contenant un graphique dans sa première feuille de calcul. Ensuite, il redimensionne et repositionne le graphique et enregistre le classeur.

Avant l’exécution du code d’exemple, le fichier source ressemble à ceci :

Taille et position du graphique avant l’exécution du code d’exemple

todo:image_alt_text

Après l’exécution, le fichier de sortie ressemble à ceci:

Taille et position du graphique après l’exécution du code d’exemple

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ChangeChartPositionAndSize.class) + "charts/";
String filePath = dataDir + "book1.xls";
Workbook workbook = new Workbook(filePath);
Worksheet worksheet = workbook.getWorksheets().get(0);
// Load the chart from source worksheet
Chart chart = worksheet.getCharts().get(0);
// Resize the chart
chart.getChartObject().setWidth(400);
chart.getChartObject().setHeight(300);
// Reposition the chart
chart.getChartObject().setX(250);
chart.getChartObject().setY(150);
// Output the file
workbook.save(dataDir + "ChangeChartPositionAndSize_out.xls");
// Print message
System.out.println("Position and Size of Chart is changed successfully.");

Manipulation des graphiques de concepteur

Il arrive que vous deviez manipuler ou modifier les graphiques dans vos fichiers de modèle de créateur. Aspose.Cells prend en charge entièrement la manipulation des graphiques du créateur avec leurs contenus et éléments. Les données, les contenus des graphiques, l’image de fond et le formatage peuvent être préservés avec précision.

Manipulation des graphiques du créateur dans les fichiers de modèle

Pour manipuler les graphiques du créateur dans un fichier de modèle, utilisez tous les appels d’API liés aux graphiques. Par exemple, utilisez la propriété Worksheet.getCharts pour obtenir la collection de graphiques existante dans le fichier de modèle.

Création d’un graphique

L’exemple suivant montre comment créer un graphique circulaire. Nous manipulerons ce graphique par la suite. La sortie suivante est générée par le code.

Le graphique circulaire d’entrée

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(CreateChart.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
// Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Adding some sample value to cells
Cells cells = sheet.getCells();
Cell cell = cells.get("A1");
cell.setValue(50);
cell = cells.get("A2");
cell.setValue(100);
cell = cells.get("A3");
cell.setValue(150);
cell = cells.get("B1");
cell.setValue(4);
cell = cells.get("B2");
cell.setValue(20);
cell = cells.get("B3");
cell.setValue(50);
ChartCollection charts = sheet.getCharts();
// Adding a chart to the worksheet
int chartIndex = charts.add(ChartType.PYRAMID, 5, 0, 15, 5);
Chart chart = charts.get(chartIndex);
// Adding NSeries (chart data source) to the chart ranging from "A1"
// cell to "B3"
SeriesCollection serieses = chart.getNSeries();
serieses.add("A1:B3", true);
// Saving the Excel file
workbook.save(dataDir + "CreateChart_out.xls");
// Print message
System.out.println("Workbook with chart is successfully created.");

Manipulation du graphique

L’exemple suivant montre comment manipuler le graphique existant. Dans cet exemple, nous modifions le graphique créé précédemment. La sortie suivante est générée par le code. Notez que la couleur du titre du graphique est passée du bleu au noir, et ‘Angleterre 30000’ a été modifié en ‘Royaume-Uni, 30K’.

Le graphique circulaire a été modifié

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ModifyPieChart.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "ModifyCharts.xlsx");
// Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(1);
// Load the chart from source worksheet
Chart chart = sheet.getCharts().get(0);
DataLabels datalabels = chart.getNSeries().get(0).getPoints().get(0).getDataLabels();
datalabels.setText("aspose");
// Saving the Excel file
workbook.save(dataDir + "ModifyPieChart_out.xls");
// Print message
System.out.println("Pie chart is successfully modified.");

Manipulation d’un graphique linéaire dans le modèle de concepteur

Dans cet exemple, nous manipulerons un graphique linéaire. Nous ajouterons des séries de données au graphique existant et changerons leurs couleurs de ligne.

Tout d’abord, jetez un œil au graphique linéaire du créateur.

Le graphique linéaire d’entrée

todo:image_alt_text

Maintenant, nous manipulons le graphique linéaire (qui est contenu dans le fichier linechart.xls) en utilisant le code suivant. La sortie suivante est générée par le code.

Le graphique linéaire manipulé

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(ModifyLineChart.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook(dataDir + "book1.xls");
// Obtaining the reference of the first worksheet
WorksheetCollection worksheets = workbook.getWorksheets();
Worksheet sheet = worksheets.get(0);
// Load the chart from source worksheet
Chart chart = sheet.getCharts().get(0);
// Adding NSeries (chart data source) to the chart ranging from "A1"
// cell to "B3"
SeriesCollection serieses = chart.getNSeries();
serieses.add("{20,40,90}", true);
serieses.add("{110,70,220}", true);
// Saving the Excel file
workbook.save(dataDir + "ModifyLineChart_out.xls");
// Print message
System.out.println("Line chart is successfully modified.");

Utilisation des sparklines

Microsoft Excel 2010 peut analyser les informations de plus de façons que jamais. Il permet aux utilisateurs de suivre et de mettre en évidence les tendances importantes des données avec de nouveaux outils d’analyse et de visualisation des données. Les sparklines sont des mini-graphiques que vous pouvez placer à l’intérieur des cellules afin de visualiser les données et le graphique sur la même table. Lorsque les sparklines sont utilisés correctement, l’analyse des données est plus rapide et plus directe. Ils offrent également une vue simple des informations, évitant les feuilles de calcul surchargées avec de nombreux graphiques complexes.

Aspose.Cells fournit une API pour manipuler les sparklines dans les feuilles de calcul.

Sparklines dans Microsoft Excel

Pour insérer des sparklines dans Microsoft Excel 2010 :

  1. Sélectionnez les cellules où vous souhaitez voir apparaître les sparklines. Pour les rendre faciles à visualiser, sélectionnez les cellules à côté des données.
  2. Cliquez sur Insérer dans le ruban, puis choisissez colonne dans le groupe Sparklines.

todo:image_alt_text

  1. Sélectionnez ou saisissez la plage de cellules dans la feuille de calcul qui contient les données source. Les graphiques apparaissent.

Les sparklines vous aident à voir les tendances, par exemple, ou le bilan des victoires ou des défaites pour une ligue de softball. Les sparklines peuvent même résumer toute la saison de chaque équipe de la ligue.

todo:image_alt_text

Sparklines en utilisant Aspose.Cells

Les développeurs peuvent créer, supprimer ou lire les sparklines (dans le fichier modèle) en utilisant l’API fournie par Aspose.Cells. En ajoutant des graphiques personnalisés pour une plage de données donnée, les développeurs ont la liberté d’ajouter différents types de petits graphiques aux zones de cellules sélectionnées.

L’exemple ci-dessous illustre la fonctionnalité des Sparklines. L’exemple montre comment :

  1. Ouvrir un fichier modèle simple.
  2. Lire les informations des sparklines pour une feuille de calcul.
  3. Ajouter de nouvelles sparklines pour une plage de données donnée à une zone de cellules.
  4. Enregistrer le fichier Excel sur le disque.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(UsingSparklines.class) + "charts/";
// Instantiating a Workbook object
Workbook workbook = new Workbook();
WorksheetCollection worksheets = workbook.getWorksheets();
// Obtaining the reference of the first worksheet
Worksheet worksheet = worksheets.get(0);
Cells cells = worksheet.getCells();
System.out.println("Sparkline count: " + worksheet.getSparklineGroupCollection().getCount());
for (int i = 0; i < worksheet.getSparklineGroupCollection().getCount(); i++) {
SparklineGroup g = worksheet.getSparklineGroupCollection().get(i);
System.out.println("sparkline group: type:" + g.getType());
for (int j = 0; j < g.getSparklineCollection().getCount(); i++) {
Sparkline gg = g.getSparklineCollection().get(i);
System.out.println("sparkline: row:" + gg.getRow() + ", col:" + gg.getColumn() + ", dataRange:"
+ gg.getDataRange());
}
}
// Add Sparklines
// Define the CellArea D2:D10
CellArea ca = new CellArea();
ca.StartColumn = 4;
ca.EndColumn = 4;
ca.StartRow = 1;
ca.EndRow = 7;
int idx = worksheet.getSparklineGroupCollection().add(SparklineType.COLUMN, "Sheet1!B2:D8", false, ca);
SparklineGroup group = worksheet.getSparklineGroupCollection().get(idx);
// Create CellsColor
CellsColor clr = workbook.createCellsColor();
clr.setColor(Color.getChocolate());
group.setSeriesColor(clr);
workbook.save(dataDir + "UsingSparklines_out.xls");
// Print message
System.out.println("Workbook with chart is created successfully.");

Application du format 3D au graphique

Vous pourriez avoir besoin de styles de graphique 3D pour obtenir les résultats correspondant à votre scénario. Les API Aspose.Cells fournissent l’API pertinente pour appliquer la mise en forme 3D de Microsoft Excel 2007 comme démontré dans cet article.

Réglage du format 3D au graphique

Un exemple complet est donné ci-dessous pour démontrer comment créer un graphique et lui appliquer la mise en forme 3D de Microsoft Excel 2007. Après l’exécution du code d’exemple ci-dessus, un graphique en colonnes (avec des effets 3D) sera ajouté à la feuille de calcul comme indiqué ci-dessous.

Un graphique en colonnes avec mise en forme 3D

todo:image_alt_text

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
// The path to the documents directory.
String dataDir = Utils.getSharedDataDir(Applying3DFormat.class) + "charts/";
// Instantiate a new Workbook
Workbook book = new Workbook();
// Add a Data Worksheet
Worksheet dataSheet = book.getWorksheets().add("DataSheet");
// Add Chart Worksheet
Worksheet sheet = book.getWorksheets().add("MyChart");
// Put some values into the cells in the data worksheet
dataSheet.getCells().get("B1").putValue(1);
dataSheet.getCells().get("B2").putValue(2);
dataSheet.getCells().get("B3").putValue(3);
dataSheet.getCells().get("A1").putValue("A");
dataSheet.getCells().get("A2").putValue("B");
dataSheet.getCells().get("A3").putValue("C");
// Define the Chart Collection
ChartCollection charts = sheet.getCharts();
// Add a Column chart to the Chart Worksheet
int chartSheetIdx = charts.add(ChartType.COLUMN, 5, 0, 25, 15);
// Get the newly added Chart
Chart chart = book.getWorksheets().get(2).getCharts().get(0);
// Set the background/foreground color for PlotArea/ChartArea
chart.getPlotArea().getArea().setBackgroundColor(Color.getWhite());
chart.getChartArea().getArea().setBackgroundColor(Color.getWhite());
chart.getPlotArea().getArea().setForegroundColor(Color.getWhite());
chart.getChartArea().getArea().setForegroundColor(Color.getWhite());
// Hide the Legend
chart.setShowLegend(false);
// Add Data Series for the Chart
chart.getNSeries().add("DataSheet!B1:B3", true);
// Specify the Category Data
chart.getNSeries().setCategoryData("DataSheet!A1:A3");
// Get the Data Series
Series ser = chart.getNSeries().get(0);
// Apply the 3D formatting
ShapePropertyCollection spPr = ser.getShapeProperties();
Format3D fmt3d = spPr.getFormat3D();
// Specify Bevel with its height/width
Bevel bevel = fmt3d.getTopBevel();
bevel.setType(BevelPresetType.CIRCLE);
bevel.setHeight(5);
bevel.setWidth(9);
// Specify Surface material type
fmt3d.setSurfaceMaterialType(PresetMaterialType.WARM_MATTE);
// Specify surface lighting type
fmt3d.setSurfaceLightingType(LightRigType.THREE_POINT);
// Specify lighting angle
fmt3d.setLightingAngle(20);
// Specify Series background/foreground and line color
ser.getArea().setBackgroundColor(Color.getMaroon());
ser.getArea().setForegroundColor(Color.getMaroon());
ser.getBorder().setColor(Color.getMaroon());
// Save the Excel file
book.save(dataDir + "A3DFormat_out.xls");
// Print message
System.out.println("3D format is applied successfully.");

Sujets avancés