Skip to content

Commit cff6020

Browse files
authored
Merge pull request #2083 from syncfusion-content/882010-DataLabel-XlsIO
882010 - Add content for adding chart data labels using range of cells
2 parents 491c168 + 6d7f6c8 commit cff6020

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed
49.9 KB
Loading

File-Formats/XlsIO/Working-with-Charts.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,53 @@ serieTwo.SerieFormat.MarkerForegroundColor = Color.DarkGreen
691691
{% endhighlight %}
692692
{% endtabs %}
693693

694+
### Different Data Label Properties
695+
696+
{% tabs %}
697+
{% highlight c# tabtitle="C# [Cross-platform]" %}
698+
IChartSerie serieOne = chart.Series[0];
699+
700+
//Set data label as value.
701+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
702+
703+
//Set data label from the range of cells
704+
serieOne.DataPoints.DefaultDataPoint.DataLabels.ValueFromCellsRange = sheet["B4:B6"];
705+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValueFromCells = true;
706+
707+
//Set the position of the data label
708+
serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Inside;
709+
{% endhighlight %}
710+
711+
{% highlight c# tabtitle="C# [Windows-specific]" %}
712+
IChartSerie serieOne = chart.Series[0];
713+
714+
//Set data label as value.
715+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
716+
717+
//Set data label from the range of cells
718+
serieOne.DataPoints.DefaultDataPoint.DataLabels.ValueFromCellsRange = sheet["B4:B6"];
719+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValueFromCells = true;
720+
721+
//Set the position of the data label
722+
serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Inside;
723+
{% endhighlight %}
724+
725+
{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %}
726+
Dim serieOne As IChartSerie = chart.Series(0)
727+
728+
'Set data label as value.
729+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValue = True
730+
731+
'Set data label from the range of cells
732+
serieOne.DataPoints.DefaultDataPoint.DataLabels.ValueFromCellsRange = sheet("B4:B6")
733+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValueFromCells = True
734+
735+
'Set the position of the data label
736+
serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Inside
737+
738+
{% endhighlight %}
739+
{% endtabs %}
740+
694741
### Different Legend Properties
695742

696743
{% tabs %}
@@ -812,7 +859,14 @@ using (ExcelEngine excelEngine = new ExcelEngine())
812859
chart.SecondaryCategoryAxis.Border.LineColor = Color.Transparent;
813860
chart.SecondaryCategoryAxis.MajorTickMark = ExcelTickMark.TickMark_None;
814861
chart.SecondaryCategoryAxis.TickLabelPosition = ExcelTickLabelPosition.TickLabelPosition_None;
862+
863+
//Set data label from the range of cells
864+
serieOne.DataPoints.DefaultDataPoint.DataLabels.ValueFromCellsRange = sheet["B4:B6"];
865+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValueFromCells = true;
815866

867+
//Set the position of the data label
868+
serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Inside;
869+
816870
//Set legend properties
817871
chart.Legend.Position = ExcelLegendPosition.Bottom;
818872
chart.Legend.IsVerticalLegend = false;
@@ -905,6 +959,13 @@ using (ExcelEngine excelEngine = new ExcelEngine())
905959
chart.SecondaryCategoryAxis.Border.LineColor = Color.Transparent;
906960
chart.SecondaryCategoryAxis.MajorTickMark = ExcelTickMark.TickMark_None;
907961
chart.SecondaryCategoryAxis.TickLabelPosition = ExcelTickLabelPosition.TickLabelPosition_None;
962+
963+
//Set data label from the range of cells
964+
serieOne.DataPoints.DefaultDataPoint.DataLabels.ValueFromCellsRange = sheet["B4:B6"];
965+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValueFromCells = true;
966+
967+
//Set the position of the data label
968+
serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Inside;
908969

909970
//Set legend properties
910971
chart.Legend.Position = ExcelLegendPosition.Bottom;
@@ -997,6 +1058,13 @@ Using excelEngine As ExcelEngine = New ExcelEngine()
9971058
chart.SecondaryCategoryAxis.MajorTickMark = ExcelTickMark.TickMark_None
9981059
chart.SecondaryCategoryAxis.TickLabelPosition = ExcelTickLabelPosition.TickLabelPosition_None
9991060

1061+
'Set data label from the range of cells
1062+
serieOne.DataPoints.DefaultDataPoint.DataLabels.ValueFromCellsRange = sheet("B4:B6")
1063+
serieOne.DataPoints.DefaultDataPoint.DataLabels.IsValueFromCells = True
1064+
1065+
'Set the position of the data label
1066+
serieOne.DataPoints.DefaultDataPoint.DataLabels.Position = ExcelDataLabelPosition.Inside
1067+
10001068
'Set legend properties
10011069
chart.Legend.Position = ExcelLegendPosition.Bottom
10021070
chart.Legend.IsVerticalLegend = False

0 commit comments

Comments
 (0)