using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Spire.Presentation;
using System.Drawing;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System.Data;
namespace Spire.Presentation
{
class Program
{
static void Main(string[] args)
{
//Create a presentation instance
Presentation presentation = new Presentation();
//Insert a column clustered chart
IChart chart = presentation.Slides[0].Shapes.AppendChart(ChartType.ColumnClustered, new RectangleF(100,100,500,300));
//Set chart title
chart.ChartTitle.TextProperties.Text = "Monthly Sales Report";
chart.ChartTitle.TextProperties.IsCentered = true;
chart.ChartTitle.Height = 30;
chart.HasTitle = true;
//Create a datatable
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("Month", Type.GetType("System.String")));
dataTable.Columns.Add(new DataColumn("Sales", Type.GetType("System.Int32")));
dataTable.Columns.Add(new DataColumn("Growth rate", Type.GetType("System.Decimal")));
dataTable.Rows.Add("January", 200, 0.6);
dataTable.Rows.Add("February", 250, 0.8);
dataTable.Rows.Add("March", 300, 0.6);
dataTable.Rows.Add("April", 150, 0.2);
//Import data from datatable to chart data
for (int c = 0; c < dataTable.Columns.Count; c++)
{
chart.ChartData[0, c].Text = dataTable.Columns[c].Caption;
}
for (int r = 0; r < dataTable.Rows.Count; r++)
{
object[] datas = dataTable.Rows[r].ItemArray;
for (int c = 0; c < datas.Length; c++)
{
chart.ChartData[r + 1, c].Value = datas[c];
}
}
//Set series labels
chart.Series.SeriesLabel = chart.ChartData["B1", "C1"];
//Set categories labels
chart.Categories.CategoryLabels = chart.ChartData["A2", "A7"];
//Assign data to series values
chart.Series[0].Values = chart.ChartData["B2", "B7"];
chart.Series[1].Values = chart.ChartData["C2", "C7"];
//Change the chart type of serie 2 to line with markers
chart.Series[1].Type = ChartType.LineMarkers;
//Plot data of series 2 on the secondary axis
chart.Series[1].UseSecondAxis = true;
//Set the number format as percentage
chart.SecondaryValueAxis.NumberFormat = "0%";
//Hide gridlinkes of secondary axis
chart.SecondaryValueAxis.MajorGridTextLines.FillType = FillFormatType.None;
//Set overlap
chart.OverLap = -50;
//Set gapwidth
chart.GapWidth = 200;
//Save and Launch
presentation.SaveToFile("AddedChart.pptx", FileFormat.Pptx2010);
System.Diagnostics.Process.Start("AddedChart.pptx");
}
}
}