Is it possible to directly add ChartEx to pptx presentation?
Something like this:
PresentationEx presColumn = new PresentationEx();
SlideEx sld = presColumn.Slides[0];
ChartEx newChart = sld.Shapes.AddChart(ChartTypeEx.StackedColumn3D, 100, 100, 550, 400);
Pay attention, insert ChartEx directly, and not using Ole object.
In other words I want to get something like in attachment.
There is .NET code, is it possible convert it to JAVA?
using System;
using System.Collections.Generic;
using System.Text;
using Aspose.Slides.Pptx;
using Aspose.Slides.Pptx.Charts;
namespace TestChart
{
class Program
{
static void Main(string[] args)
{
//Instantiate PresentationEx class that represents PPTX file
PresentationEx pres = new PresentationEx();
//Access first slide
SlideEx sld = pres.Slides[0];
// Add chart with default data
ChartEx chart = sld.Shapes.AddChart(ChartTypeEx.ClusteredColumn, 0, 0, 500, 500);
//Setting chart Title
chart.ChartTitle.Text.Text = "Sample Title";
chart.ChartTitle.Text.CenterText = true;
chart.ChartTitle.Height = 20;
chart.HasTitle = true;
//Set first series to Show Values
chart.ChartData.Series[0].Labels.ShowValue = true;
//Setting the index of chart data sheet
int defaultWorksheetIndex = 0;
//Getting the chart data worksheet
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
//Delete default generated series and categories
chart.ChartData.Series.Clear();
chart.ChartData.Categories.Clear();
int s = chart.ChartData.Series.Count;
s = chart.ChartData.Categories.Count;
//Adding new series
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.Type);
chart.ChartData.Series.Add(fact.GetCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.Type);
//Adding new categories
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2"));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3"));
//Take first chart series
ChartSeriesEx series = chart.ChartData.Series[0];
//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 1, 20));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 1, 50));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 1, 30));
//Take second chart series
series = chart.ChartData.Series[1];
//Now populating series data
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 1, 2, 30));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 2, 2, 10));
series.Values.Add(fact.GetCell(defaultWorksheetIndex, 3, 2, 60));
//create custom lables for each of categories for new series
//first label will be show Category name
DataLabelEx lbl = new DataLabelEx(series);
lbl.ShowCategoryName = true;
lbl.Id = 0;
series.Labels.Add(lbl);
//Show series name for second label
lbl = new DataLabelEx(series);
lbl.ShowSeriesName = true;
lbl.Id = 1;
series.Labels.Add(lbl);
//show value for third label
lbl = new DataLabelEx(series);
lbl.ShowValue = true;
lbl.ShowSeriesName = true;
lbl.Separator = "/";
lbl.Id = 2;
series.Labels.Add(lbl);
// show value and custom text
// lbl = new DataLabelEx(series);
// lbl.TextFrame.Text = "My text";
// lbl.Id = 3;
// ser.Labels.Add(lbl);
// Save presentation with chart
pres.Write(@"..\..\AsposeChart.pptx");
}
}
}