Hi,
I would like to build chart which is similar to chart in attached file. Category axis includes dates. I use code from this site: Create or Update PowerPoint Presentation Charts in C# or .NET|Aspose.Slides Documentation in categories I am using DateTime objects:
//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
DateTime dateTime1 = new DateTime(1990, 1, 1);
DateTime dateTime2 = new DateTime(1992, 1, 1);
DateTime dateTime3 = new DateTime(1993, 1, 1);
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 1, 0, dateTime1));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 2, 0, dateTime2));
chart.ChartData.Categories.Add(fact.GetCell(defaultWorksheetIndex, 3, 0, dateTime3));
//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;
series.Labels.Add(lbl);
// Save presentation with chart
pres.Write(@"C:\AsposeChart.pptx");
When I try to edit generated chart data, the dates are numbers. I also would like to format dates to remove hours, minutes and seconds.
How to style chart title (change font color and font size) the same as in attached file?
Best regards,
Piotr