차트 데이터 레이블 작업
Contents
[
Hide
]
Aspose.Words 사용자가 작업 할 수 있습니다 ChartDataLabel 다양한 방법.
차트 데이터 레이블 수를 포맷하는 방법
사용 NumberFormat 차트의 단일 데이터 레이블의 숫자 서식을 지정할 수 있습니다.
다음 코드 예제에서는 데이터 레이블의 번호를 포맷하는 방법을 보여 줍니다:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
// Add chart with default data. | |
System::SharedPtr<Shape> shape = builder->InsertChart(ChartType::Line, 432, 252); | |
System::SharedPtr<Chart> chart = shape->get_Chart(); | |
chart->get_Title()->set_Text(u"Data Labels With Different Number Format"); | |
// Delete default generated series. | |
chart->get_Series()->Clear(); | |
// Add new series | |
System::SharedPtr<ChartSeries> series1 = chart->get_Series()->Add(u"AW Series 1", System::MakeArray<System::String>({u"AW0", u"AW1", u"AW2"}), System::MakeArray<double>({2.5, 1.5, 3.5})); | |
series1->set_HasDataLabels(true); | |
series1->get_DataLabels()->set_ShowValue(true); | |
series1->get_DataLabels()->idx_get(0)->get_NumberFormat()->set_FormatCode(u"\"$\"#,##0.00"); | |
series1->get_DataLabels()->idx_get(1)->get_NumberFormat()->set_FormatCode(u"dd/mm/yyyy"); | |
series1->get_DataLabels()->idx_get(2)->get_NumberFormat()->set_FormatCode(u"0.00%"); | |
// Or you can set format code to be linked to a source cell, | |
// in this case NumberFormat will be reset to general and inherited from a source cell. | |
series1->get_DataLabels()->idx_get(2)->get_NumberFormat()->set_IsLinkedToSource(true); | |
System::String outputPath = outputDataDir + u"ChartNumberFormat.docx"; | |
doc->Save(outputPath); |
차트 데이터 레이블 작업 방법
사용 ChartDataLabel 표시/숨기기와 같이 차트 계열의 단일 데이터 레이블의 서식을 지정할 수 있습니다 LegendKey, CategoryName, SeriesName,가치 등:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
System::SharedPtr<Shape> shape = builder->InsertChart(ChartType::Bar, 432, 252); | |
System::SharedPtr<Chart> chart = shape->get_Chart(); | |
// Get first series. | |
System::SharedPtr<ChartSeries> series0 = shape->get_Chart()->get_Series()->idx_get(0); | |
System::SharedPtr<ChartDataLabelCollection> labels = series0->get_DataLabels(); | |
// Set properties. | |
labels->set_ShowLegendKey(true); | |
// By default, when you add data labels to the data points in a pie chart, leader lines are displayed for data labels that are | |
// Positioned far outside the end of data points. Leader lines create a visual connection between a data label and its | |
// Corresponding data point. | |
labels->set_ShowLeaderLines(true); | |
labels->set_ShowCategoryName(false); | |
labels->set_ShowPercentage(false); | |
labels->set_ShowSeriesName(true); | |
labels->set_ShowValue(true); | |
labels->set_Separator(u"/"); | |
labels->set_ShowValue(true); | |
System::String outputPath = outputDataDir + u"SimpleBarChart_out.docx"; | |
doc->Save(outputPath); |
아래 결과를 참조하십시오: