Làm Việc Với Nhãn Dữ Liệu Biểu Đồ

Aspose.Words cho phép người dùng làm việc với ChartDataLabel một cách khác nhau.

Cách Định Dạng Số Nhãn Dữ liệu Biểu Đồ

Sử dụng NumberFormat bạn có thể chỉ định định dạng số của một nhãn dữ liệu duy nhất của biểu đồ.

Ví dụ mã sau đây cho thấy cách định dạng một số nhãn dữ liệu:

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);

Cách Làm Việc Với Nhãn Dữ Liệu Biểu Đồ

Sử dụng ChartDataLabel bạn có thể chỉ định định dạng của một nhãn dữ liệu duy nhất của chuỗi biểu đồ, như hiển thị / ẩn LegendKey, CategoryName, SeriesName, Giá trị vv:

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);

Vui lòng xem kết quả bên dưới:

work-with-chart-data-lable-aspose-words-cpp-1