Hello,
I want to change chart data as I mention in attachment?
Series has Values list and each value is CellRange and CellRange has Text property. Can I set Text property like attachment?
//Get chart on the first slide
IChart Chart = ppt.Slides[0].Shapes[0] as IChart;
//Show data labels
Chart.Series[0].DataLabels.LabelValueVisible = true;
chart.Series[x].Values
chart.Series[x].DataLabels
chart.ChartData[x, 0].Value="2.9"
for (int i = 0; i < chart.Categories.Count; i++)
{
chart.Series[0].DataLabels.Add();
}
IChart chart = presentation.Slides[0].Shapes[0] as IChart;
for (int i = 0; i < chart.Categories.Count; i++)
{
chart.Series[0].DataLabels.Add();
}
chart.Series[0].DataLabels.LabelValueVisible = true;
float fontHeight = 10;
TextFont latinFont = new TextFont("Calibri");
FillFormatType fillType = Spire.Presentation.Drawing.FillFormatType.Solid;
Color color = System.Drawing.Color.Black;
ChartDataLabelCollection ss = chart.Series[0].DataLabels;
ITextFrameProperties textFrame = chart.Series[0].DataLabels[0].TextFrame;
TextParagraph paragraph = textFrame.Paragraphs[0];
TextRange topTextRange = new TextRange("Top");
topTextRange.LatinFont = latinFont;
topTextRange.FontHeight = fontHeight;
topTextRange.Fill.FillType = fillType;
topTextRange.Fill.SolidColor.Color = color;
paragraph.TextRanges.Append(topTextRange);
TextParagraph newPara1= new TextParagraph();
TextRange leftTextRange = new TextRange("left");
leftTextRange.LatinFont = latinFont;
leftTextRange.FontHeight = fontHeight;
leftTextRange.Fill.FillType = fillType;
leftTextRange.Fill.SolidColor.Color = color;
newPara1.TextRanges.Insert(0, leftTextRange);
TextRange middleTextRange = new TextRange(" ↑ ");
middleTextRange.LatinFont = latinFont;
middleTextRange.FontHeight = fontHeight;
middleTextRange.Fill.FillType = fillType;
middleTextRange.Fill.SolidColor.Color = Color.Blue;
newPara1.TextRanges.Append(middleTextRange);
TextRange rightTextRange = new TextRange("right");
rightTextRange.LatinFont = latinFont;
rightTextRange.FontHeight = fontHeight;
rightTextRange.Fill.FillType = fillType;
rightTextRange.Fill.SolidColor.Color = color;
newPara1.TextRanges.Append(rightTextRange);
textFrame.Paragraphs.Append(newPara1);
TextParagraph newPara2 = new TextParagraph();
TextRange bottomtextRange = new TextRange("bottom");
bottomtextRange.LatinFont = latinFont;
bottomtextRange.FontHeight = fontHeight;
bottomtextRange.Fill.FillType = fillType;
bottomtextRange.Fill.SolidColor.Color = color;
newPara2.TextRanges.Append(bottomtextRange);
textFrame.Paragraphs.Append(newPara2);
for (int x = 0; x < chart.Series.Count; x++)
{
for (int i = 0; i < chart.Categories.Count; i++)
{
chart.Series[x].DataLabels.Add();
ITextFrameProperties textFrame = chart.Series[x].DataLabels[0].TextFrame;
TextParagraph paragraph = textFrame.Paragraphs[0];
TextRange topTextRange = new TextRange("Top");
paragraph.TextRanges.Append(topTextRange);
TextParagraph newPara1 = new TextParagraph();
TextRange leftTextRange = new TextRange("left");
newPara1.TextRanges.Insert(0, leftTextRange);
TextRange middleTextRange = new TextRange(" ↑ ");
newPara1.TextRanges.Append(middleTextRange);
TextRange rightTextRange = new TextRange("right");
newPara1.TextRanges.Append(rightTextRange);
textFrame.Paragraphs.Append(newPara1);
TextParagraph newPara2 = new TextParagraph();
TextRange bottomtextRange = new TextRange("bottom");
newPara2.TextRanges.Append(bottomtextRange);
textFrame.Paragraphs.Append(newPara2);
}
}
static void AddMultipleTextRange()
{
Presentation presentation = new Presentation();
presentation.LoadFromFile(@"source_template_chart.pptx");
//Get chart on the first slide
IChart chart = presentation.Slides[0].Shapes[0] as IChart;
float fontHeight = 10;
TextFont latinFont = new TextFont("Calibri");
FillFormatType fillType = Spire.Presentation.Drawing.FillFormatType.Solid;
Color color = System.Drawing.Color.Black;
for (int s = 0; s < chart.Series.Count; s++)
{
chart.Series[s].DataLabels.LabelValueVisible = true;
for (int j = 0; j < chart.Categories.Count; j++)
{
ChartDataLabel dataLabel = chart.Series[s].DataLabels.Add();
ITextFrameProperties textFrame = dataLabel.TextFrame;
TextParagraph paragraph = textFrame.Paragraphs[0];
TextRange topTextRange = new TextRange("Top");
topTextRange.LatinFont = latinFont;
topTextRange.FontHeight = fontHeight;
topTextRange.Fill.FillType = fillType;
topTextRange.Fill.SolidColor.Color = color;
paragraph.TextRanges.Append(topTextRange);
TextParagraph newPara1 = new TextParagraph();
TextRange leftTextRange = new TextRange("left");
leftTextRange.LatinFont = latinFont;
leftTextRange.FontHeight = fontHeight;
leftTextRange.Fill.FillType = fillType;
leftTextRange.Fill.SolidColor.Color = color;
newPara1.TextRanges.Insert(0, leftTextRange);
TextRange middleTextRange = new TextRange(" ↑ ");
middleTextRange.LatinFont = latinFont;
middleTextRange.FontHeight = fontHeight;
middleTextRange.Fill.FillType = fillType;
middleTextRange.Fill.SolidColor.Color = Color.Blue;
newPara1.TextRanges.Append(middleTextRange);
TextRange rightTextRange = new TextRange("right");
rightTextRange.LatinFont = latinFont;
rightTextRange.FontHeight = fontHeight;
rightTextRange.Fill.FillType = fillType;
rightTextRange.Fill.SolidColor.Color = color;
newPara1.TextRanges.Append(rightTextRange);
textFrame.Paragraphs.Append(newPara1);
TextParagraph newPara2 = new TextParagraph();
TextRange bottomtextRange = new TextRange("bottom");
bottomtextRange.LatinFont = latinFont;
bottomtextRange.FontHeight = fontHeight;
bottomtextRange.Fill.FillType = fillType;
bottomtextRange.Fill.SolidColor.Color = color;
newPara2.TextRanges.Append(bottomtextRange);
textFrame.Paragraphs.Append(newPara2);
}
}
String result = "source_template_chart-out.pptx";
presentation.SaveToFile(result, Spire.Presentation.FileFormat.Pptx2013);
}
middleTextRange.Fill.SolidColor.Color = chart.Series[s].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.SolidColor.Color;
middleTextRange.Fill.FillType= chart.Series[s].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.Fill.FillType;
middleTextRange.FontHeight = chart.Series[s].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.FontHeight;
middleTextRange.LatinFont = chart.Series[s].DataLabels.TextProperties.Paragraphs[0].DefaultCharacterProperties.LatinFont;
middleTextRange.Fill.SolidColor.Color = chart.Series[s].DataLabels[j].TextFrame.Paragraphs[1].TextRanges[1].Fill.SolidColor.Color;
middleTextRange.Fill.FillType = chart.Series[s].DataLabels[j].TextFrame.Paragraphs[1].TextRanges[1].Fill.FillType;
middleTextRange.FontHeight = chart.Series[s].DataLabels[j].TextFrame.Paragraphs[1].TextRanges[1].FontHeight;
middleTextRange.LatinFont = chart.Series[s].DataLabels[j].TextFrame.Paragraphs[1].TextRanges[1].LatinFont;
chart.Series[s].DataLabels
chart.Series[s].DataLabels.Add();
middleTextRange.Fill.SolidColor.Color = chart.Series[s].DataLabels[0].TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color;
middleTextRange.Fill.FillType = chart.Series[s].DataLabels[0].TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType;
middleTextRange.FontHeight = chart.Series[s].DataLabels[0].TextFrame.Paragraphs[0].TextRanges[0].FontHeight;
middleTextRange.LatinFont = chart.Series[s].DataLabels[0].TextFrame.Paragraphs[0].TextRanges[0].LatinFont;