Hi guys,
Basically I want to change color and width of PrimaryValueAxis though couldn't found any relevant properties there.
Can you help me with that? Please see attachment to see what I want to achieve
Thanks.
IChart chart = presentation.Slides[0].Shapes[0] as IChart;
//SecondaryValueAxis is for Y axis and PrimaryValueAxis is for X axixs.
chart.SecondaryValueAxis.ChartEffectFormat.Line.FillType = FillFormatType.Solid;
chart.SecondaryValueAxis.ChartEffectFormat.Line.Width = 2;
chart.SecondaryValueAxis.ChartEffectFormat.Line.FillFormat.SolidFillColor.Color = Color.Red;
IChart chart = templatePresentation.Slides[0].Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
//SecondaryValueAxis is for Y axis and PrimaryValueAxis is for X axixs.
var chartFillType = chart.PrimaryCategoryAxis.ChartEffectFormat.Line.FillType;
var chartWidth = chart.PrimaryCategoryAxis.ChartEffectFormat.Line.Width;
var chartLineColor = chart.PrimaryCategoryAxis.ChartEffectFormat.Line.FillFormat.SolidFillColor.Color;
Debug.WriteLine("chartFillType-PrimaryCategoryAxis:" + chartFillType);
Debug.WriteLine("chartWidth-PrimaryCategoryAxis:" + chartWidth);
Debug.WriteLine("chartLineColor-PrimaryCategoryAxis:" + chartLineColor);
Presentation templatePresentation = new Presentation();
templatePresentation.LoadFromFile("example_template2.pptx");
templatePresentation.SaveToFile("result.pptx",FileFormat.Pptx2013);
using Newtonsoft.Json.Linq;
using Spire.Presentation;
using Spire.Presentation.Charts;
using System;
using System.Linq;
namespace PptxTester
{
class Program
{
static void Main(string[] args)
{
//Load template presentation
Presentation templatePresentation = new Presentation();
templatePresentation.LoadFromFile("example_template2.pptx");
//Create new presentation
Spire.Presentation.Presentation newPresentation = new Spire.Presentation.Presentation();
newPresentation.Slides.RemoveAt(0);
//Get first slide from template presentation
var slide = templatePresentation.Slides[0];
//Change Chart Data
IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
chart.ChartData[0, 1].Value = "Series 1";
chart.ChartData[1, 0].Value = "Male";
chart.ChartData[2, 0].Value = "Female";
chart.ChartData[1, 1].Value = 0.1;
chart.ChartData[2, 1].Value = 0.9;
int categoryCount = 2;
int seriesCount = 1;
chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];
for (int i = 0; i < seriesCount; i++)
{
string letter = GetColumnName(i + 1);
chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
}
//------------------------------------------------------------------------------------------
//Append first slide to new presentation
newPresentation.Slides.Append(slide);
//Save presentation
newPresentation.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
static string GetColumnName(int index)
{
const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var value = "";
if (index >= letters.Length)
value += letters[index / letters.Length - 1];
value += letters[index % letters.Length];
return value;
}
}
}
IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
//Get original fill format of series
List<FillFormat> fillFormat = new List<FillFormat>();
for (int j = 0; j < chart.Series.Count; j++)
{
fillFormat.Add(chart.Series[j].Fill);
}
.....
chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];
//Set the fill format for Series
for (int j = 0; j < chart.Series.Count; j++)
{
chart.Series[j].Fill.FillType = fillFormat[j].FillType;
chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
}
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PptxTester
{
class Program
{
static void Main(string[] args)
{
//Load template presentation
Presentation templatePresentation = new Presentation();
templatePresentation.LoadFromFile("example_template2.pptx");
//Create new presentation
Spire.Presentation.Presentation newPresentation = new Spire.Presentation.Presentation();
newPresentation.Slides.RemoveAt(0);
//Get first slide from template presentation
var slide = templatePresentation.Slides[0];
//Change Chart Data
IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 23") as IChart;
//Get original fill format of series
List<FillFormat> fillFormat = new List<FillFormat>();
for (int j = 0; j < chart.Series.Count; j++)
{
fillFormat.Add(chart.Series[j].Fill);
}
chart.ChartData[0, 1].Value = "Series 1";
chart.ChartData[1, 0].Value = "Male";
chart.ChartData[2, 0].Value = "Female";
chart.ChartData[1, 1].Value = 0.1;
chart.ChartData[2, 1].Value = 0.5;
int categoryCount = 2;
int seriesCount = 1;
chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];
//Set the fill format for Series
for (int j = 0; j < chart.Series.Count; j++)
{
chart.Series[j].Fill.FillType = fillFormat[j].FillType;
chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
}
for (int i = 0; i < seriesCount; i++)
{
string letter = GetColumnName(i + 1);
chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
}
//------------------------------------------------------------------------------------------
//Append first slide to new presentation
newPresentation.Slides.Append(slide);
//Save presentation
newPresentation.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
static string GetColumnName(int index)
{
const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var value = "";
if (index >= letters.Length)
value += letters[index / letters.Length - 1];
value += letters[index % letters.Length];
return value;
}
}
}
//Set the fill format for Series
for (int j = 0; j < chart.Series.Count; j++)
{
chart.Series[j].Fill.FillType = fillFormat[j].FillType;
chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
//Add and set data labels
for (int i = 0; i < 2; i++)
{
ChartDataLabel dataLabel = chart.Series[j].DataLabels.Add();
dataLabel.HasDataSource = false;
dataLabel.LabelValueVisible = true;
dataLabel.NumberFormat = "0%";
}
}
using Spire.Presentation;
using Spire.Presentation.Charts;
using Spire.Presentation.Drawing;
using System;
using System.Collections.Generic;
using System.Linq;
namespace PptxTester
{
class Program
{
static void Main(string[] args)
{
//Load template presentation
Presentation templatePresentation = new Presentation();
templatePresentation.LoadFromFile("example_template2.pptx");
//Create new presentation
Spire.Presentation.Presentation newPresentation = new Spire.Presentation.Presentation();
newPresentation.Slides.RemoveAt(0);
//Get first slide from template presentation
var slide = templatePresentation.Slides[5];
//Change Chart Data
IChart chart = slide.Shapes.ToArray().FirstOrDefault(x => x.Name == "Chart 33") as IChart;
//Get original fill format of series
List<FillFormat> fillFormat = new List<FillFormat>();
for (int j = 0; j < chart.Series.Count; j++)
{
fillFormat.Add(chart.Series[j].Fill);
}
chart.ChartData[0, 1].Value = "Break 1";
chart.ChartData[0, 2].Value = "Break 2";
chart.ChartData[0, 3].Value = "Break 3";
chart.ChartData[1, 0].Value = "I would look at what other concerts are available from NETWORK through streaming or their app";
chart.ChartData[2, 0].Value = "I would look for what other content NETWORK has available through streaming or their app";
chart.ChartData[3, 0].Value = "I would visit NETWORK.org";
chart.ChartData[4, 0].Value = "I would visit my local NETWORK station’s website";
chart.ChartData[1, 1].Value = 0.2;
chart.ChartData[1, 2].Value = 0.6;
chart.ChartData[1, 3].Value = 0.2;
chart.ChartData[2, 1].Value = 0.7;
chart.ChartData[2, 2].Value = 0.2;
chart.ChartData[2, 3].Value = 0.1;
chart.ChartData[3, 1].Value = 0.7;
chart.ChartData[3, 2].Value = 0.2;
chart.ChartData[3, 3].Value = 0.1;
chart.ChartData[4, 1].Value = 0.5;
chart.ChartData[4, 2].Value = 0.2;
chart.ChartData[4, 3].Value = 0.3;
int categoryCount = 4;
int seriesCount = 3;
chart.Series.SeriesLabel = chart.ChartData["B1", GetColumnName(seriesCount) + "1"];
//Set the fill format for Series
for (int j = 0; j < chart.Series.Count; j++)
{
chart.Series[j].Fill.FillType = fillFormat[j].FillType;
chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
}
for (int j = 0; j < chart.Series.Count; j++)
{
chart.Series[j].Fill.FillType = fillFormat[j].FillType;
chart.Series[j].Fill.SolidColor.Color = fillFormat[j].SolidColor.Color;
//Add and set data labels
for (int i = 0; i < 4; i++)
{
ChartDataLabel dataLabel = chart.Series[j].DataLabels.Add();
dataLabel.HasDataSource = false;
dataLabel.LabelValueVisible = true;
dataLabel.NumberFormat = "0%";
}
}
for (int i = 0; i < seriesCount; i++)
{
string letter = GetColumnName(i + 1);
chart.Series[i].Values = chart.ChartData[letter + "2", letter + (categoryCount + 1)];
}
//------------------------------------------------------------------------------------------
//Append first slide to new presentation
newPresentation.Slides.Append(slide);
//Save presentation
newPresentation.SaveToFile("result.pptx", FileFormat.Pptx2013);
}
static string GetColumnName(int index)
{
const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var value = "";
if (index >= letters.Length)
value += letters[index / letters.Length - 1];
value += letters[index % letters.Length];
return value;
}
}
}