Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 109 additions & 1 deletion File-Formats/DocIO/Charts/Chart-Title.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,112 @@ End Using
{% endhighlight %}
{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Charts/Format-Chart-Title/.NET).
You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Charts/Format-Chart-Title/.NET).

## Remove Chart Title

The following code example illustrates how to remove the chart title from the Word document.

{% tabs %}

{% highlight c# tabtitle="C# [Cross-platform]" %}
//Creates a new instance of WordDocument.
using (WordDocument document = new WordDocument())
{
//Adds section to the document.
IWSection sec = document.AddSection();
//Adds paragraph to the section.
IWParagraph paragraph = sec.AddParagraph();
//Creates and Appends chart to the paragraph.
WChart chart = paragraph.AppendChart(446, 270);
//Sets chart type.
chart.ChartType = OfficeChartType.Pie;
//Sets chart title.
chart.ChartTitle = string.Empty;
//Sets data for chart.
chart.ChartData.SetValue(1, 1, "");
chart.ChartData.SetValue(1, 2, "Sales");
chart.ChartData.SetValue(2, 1, "Phyllis Lapin");
chart.ChartData.SetValue(2, 2, 141.396);
chart.ChartData.SetValue(3, 1, "Stanley Hudson");
chart.ChartData.SetValue(3, 2, 80.368);
//Creates a new chart series with the name “Sales”.
IOfficeChartSerie pieSeries = chart.Series.Add("Sales");
pieSeries.Values = chart.ChartData[2, 2, 3, 2];
//Sets category labels.
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 3, 1];
//Saves the Word document to MemoryStream.
MemoryStream stream = new MemoryStream();
document.Save(stream, FormatType.Docx);
//Closes the document.
document.Close();
}
{% endhighlight %}

{% highlight c# tabtitle="C# [Windows-specific]" %}
//Creates a new instance of WordDocument.
using (WordDocument document = new WordDocument())
{
//Adds section to the document.
IWSection sec = document.AddSection();
//Adds paragraph to the section.
IWParagraph paragraph = sec.AddParagraph();
//Creates and Appends chart to the paragraph.
WChart chart = paragraph.AppendChart(446, 270);
//Sets chart type.
chart.ChartType = OfficeChartType.Pie;
//Sets chart title.
chart.ChartTitle = string.Empty;
//Sets data for chart.
chart.ChartData.SetValue(1, 1, "");
chart.ChartData.SetValue(1, 2, "Sales");
chart.ChartData.SetValue(2, 1, "Phyllis Lapin");
chart.ChartData.SetValue(2, 2, 141.396);
chart.ChartData.SetValue(3, 1, "Stanley Hudson");
chart.ChartData.SetValue(3, 2, 80.368);
//Creates a new chart series with the name “Sales”.
IOfficeChartSerie pieSeries = chart.Series.Add("Sales");
pieSeries.Values = chart.ChartData[2, 2, 3, 2];
//Sets category labels.
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 3, 1];
//Saves the document
document.Save("Sample.docx");
//Closes the document.
document.Close();
}
{% endhighlight %}

{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
'Creates an empty WordDocument instance
Dim document As New WordDocument()
'Adds section to the document.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some code snippet are missing. Please confirm does this code works properly

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added them missed code. Ensured the code that it is working.

Dim sec As IWSection = document.AddSection()
'Adds paragraph to the section.
Dim paragraph As IWParagraph = sec.AddParagraph()
'Creates and Appends chart to the paragraph.
Dim chart As WChart = paragraph.AppendChart(446,270)
'Sets chart type.
chart.ChartType = OfficeChartType.Pie
'Sets chart title.
chart.ChartTitle = String.Empty
'Sets data for chart.
chart.ChartData.SetValue(1, 1, "")
chart.ChartData.SetValue(1, 2, "Sales")
chart.ChartData.SetValue(2, 1, "Phyllis Lapin")
chart.ChartData.SetValue(2, 2, 141.396)
chart.ChartData.SetValue(3, 1, "Stanley Hudson")
chart.ChartData.SetValue(3, 2, 80.368)
'Creates a new chart series with the name “Sales”.
Dim pieSeries As IOfficeChartSerie = chart.Series.Add("Sales")
pieSeries.Values = chart.ChartData(2, 2, 3, 2)
'Sets category labels.
chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData(2, 1, 3, 1)
'Saves the document
document.Save("Sample.docx", FormatType.Docx)
'Closes the document
document.Close()
{% endhighlight %}

{% endtabs %}

You can download a complete working sample from [GitHub](https://github.com/SyncfusionExamples/DocIO-Examples/tree/main/Charts/Remove-chart-title).
2 changes: 1 addition & 1 deletion File-Formats/DocIO/Working-with-Charts.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,4 +1257,4 @@ The following chart types are supported in DocIO.
* [How to create line chart with different color series in Word document using C#?](https://support.syncfusion.com/kb/article/12275/how-to-create-line-chart-with-different-color-series-in-word-document-using-c)
* [How to set column space for column charts in Word document?](https://support.syncfusion.com/kb/article/12296/how-to-set-column-space-for-column-charts-in-word-document)
* [How to set Y-axis interval for column charts in Word document?](https://support.syncfusion.com/kb/article/12294/how-to-set-y-axis-interval-for-column-charts-in-word-document)
* [How to change chart title position in the Word document?](https://support.syncfusion.com/kb/article/12292/how-to-change-chart-title-position-in-the-word-document)
* [How to change chart title position in the Word document?](https://support.syncfusion.com/kb/article/12292/how-to-change-chart-title-position-in-the-word-document)