3D Charts in UWP Charts (SfChart)
7 Jan 202511 minutes to read
3D charts are used to view two-dimensional data in a three-dimensional view, and can be rotated in all 3 dimensions to get the best possible view of the data.
Key features
- Eight types of chart
Series
. - Perspective view.
- Data binding.
- Animations.
- Empty point support.
- Dynamic update.
- Dynamic rotation.
- Selection support.
Creating 3D Charts
The following steps explain how to create 3D charts.
- Open the Add Reference window from your project.
- Choose Windows > Extensions > Syncfusion controls for UWP XAML.
- Add the following namespace in your XAML page:
xmlns:Syncfusion="using:Syncfusion.UI.Xaml.Charts"
- Initialize the chart represented by the following class, Syncfusion.UI.Xaml.Charts.SfChart3D:
<Syncfusion:SfChart3D>
</Syncfusion:SfChart3D>
- Next, declare the
PrimaryAxis
andSecondaryAxis
:
<Syncfusion:SfChart3D>
<Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:CategoryAxis3D/>
</Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:NumericalAxis3D/>
</Syncfusion:SfChart3D.SecondaryAxis>
</Syncfusion:SfChart3D >
Add Chart Series to Chart
To begin with plotting data choose from a wide variety of graphical representations available in the Chart library (e.g., 3DColumn series, 3D PieSeries). The graph selected will depend on the scenario of the user and the nature of the data.
<Syncfusion:SfChart3D x:Name="Chart">
<Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:DateTimeAxis3D/>
</Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:NumericalAxis3D/>
</Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:ColumnSeries3D/>
</Syncfusion:SfChart3D>
Create a Sample Data Source
Since the above step will produce only an empty column 3D chart, plotting data must be added to the chart. This step illustrates how to create a sample data source. The data source must implement the IEnumerable interface.
public class UserProfile
{
public DateTime TimeStamp { get; set; }
public double NoOfUsers { get; set; }
}
public class UsersViewModel
{
public UsersViewModel()
{
this.UsersList = new ObservableCollection<UserProfile>();
DateTime date = DateTime.Today;
UsersList.Add(new UserProfile { TimeStamp=date.AddHours(0.5),NoOfUsers=1000});
UsersList.Add(new UserProfile { TimeStamp=date.AddHours(0.5),NoOfUsers = 5000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 3000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 4000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 2000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 1000 });
}
public ObservableCollection<UserProfile> UsersList
{
get; set;
}
}
Binding Data to ChartSeries
Add the above UsersViewModel to the DataContext of the chart, bind the data source to the ItemsSource
property of the 3D column series, and then map the data using XBindingPath
and YBindingPath
properties.
<Page.DataContext>
<local:UsersViewModel/>
</ Page.DataContext>
<Syncfusion:SfChart3D x:Name="Chart" Height="500" Width="500">
<Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:CategoryAxis3D/>
</Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:NumericalAxis3D/>
</Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:ColumnSeries3D
ItemsSource="{Binding UsersList}"
XBindingPath="TimeStamp"
YBindingPath="NoOfUsers">
</Syncfusion:ColumnSeries3D>
</Syncfusion:SfChart3D >
The following screenshot illustrates the result of the above code sample:
Adornments
Adornments
are used to indicate corresponding data point values and can be customized using the following properties:
Property | Description |
---|---|
Gets or sets ability to show and hide the connector line for adornments. | |
Gets or sets the connector line style. | |
Gets or sets the connector line rotate angle. | |
Gets or sets the connector height. | |
Gets or sets the adornments label template. | |
Enum property to get or set the symbol for adornments. | |
Gets or sets the height for the symbol. | |
Gets or sets the width for the symbol. | |
Gets or sets the symbol template. | |
Gets or sets the interior for the symbol. | |
Gets or sets the stroke for the symbol. | |
An enum property allowed to position the adornments TopAndBottom, Bottom and Top areas. | |
Gets or sets the actual label content to be displayed in the label. | |
Gets or sets the adornments label format. | |
A Boolean property to show or hide the markers. | |
A Boolean property to show or hide the labels |
Series
Series Types
- Column
- Bar
- Stacking column
- Stacking column 100
- Stacking bar
- Stacking bar
- Pie
- Doughnut
Create a simple chart series
The following code can be used to create a simple doughnut series:
<Page.DataContext>
<local:UsersViewModel/>
</Page.DataContext>
<Syncfusion:SfChart3D x:Name="Chart" Height="500" Width="500">
<Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:CategoryAxis3D/>
</Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:NumericalAxis3D/>
</Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:DoughnutSeries3D
ItemsSource="{Binding UsersList}"
XBindingPath="TimeStamp"
YBindingPath="NoOfUsers">
</Syncfusion:DoughnutSeries3D>
</Syncfusion:SfChart3D >
public class UserProfile
{
public DateTime TimeStamp { get; set; }
public double NoOfUsers { get; set; }
}
public class UsersViewModel
{
public UsersViewModel()
{
this.UsersList = new ObservableCollection<UserProfile>();
DateTime date = DateTime.Today;
UsersList.Add(new UserProfile { TimeStamp=date.AddHours(0.5),NoOfUsers=1000});
UsersList.Add(new UserProfile { TimeStamp=date.AddHours(0.5),NoOfUsers = 5000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 3000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 4000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 2000 });
UsersList.Add(new UserProfile { TimeStamp = date.AddHours(0.5), NoOfUsers = 1000 });
}
public ObservableCollection<UserProfile> UsersList
{
get; set;
}
}
The following image illustrates the result of the above code sample:
Interactivity
3D charts provide interactive features such as dynamic rotation, segment selection, and dynamic segment explode for circular series.
Dynamic rotation
3D charts allow us to view the best possible view of data dynamically using a mouse or touch device. To enable dynamic rotation, set the EnableRotation
property to true.
The following code example illustrates how to enable the dynamic rotation:
<Syncfusion:SfChart3D EnableRotation="True" x:Name="Chart" Height="500" Width="600">
SegmentSelection
To enable segment selection in a 3D chart, set the SegmentSelectionBrush
property in chart series.
The following code example illustrates how to set the selection brush for individual series. For data refer to the Series category in 3D charts.
<Syncfusion:SfChart3D EnableRotation="True" x:Name="Chart"
Height="500" Width="600">
<Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:CategoryAxis3D/>
</Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:NumericalAxis3D/>
</Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:ColumnSeries3D
SegmentSelectionBrush="Red"
ItemsSource="{Binding UsersList}"
XBindingPath="TimeStamp"
YBindingPath="NoOfUsers">
</Syncfusion:ColumnSeries3D>
</Syncfusion:SfChart3D >
The following screenshot illustrates the result of the above code example.
SeriesSelection
Series selection support is used to highlight the series programmatically or by user interaction. Also you can get a SeriesSelectedIndex
, PreviousSelectedIndex
value in SelectionChanged
event arguments.
The following code example can be used to set series selection in a SfChart3D
.
<chart:SfChart3D EnableSeriesSelection="True" SeriesSelectedIndex="0">
<chart:ColumnSeries3D XBindingPath="FruitName"
SeriesSelectionBrush="Blue"
YBindingPath="People1"
ItemsSource="{Binding Fruits}">
<chart:ColumnSeries3D.AdornmentsInfo>
<chart:ChartAdornmentInfo3D AdornmentsPosition="TopAndBottom"
ShowLabel="true"
HighlightOnSelection="True"/>
</chart:ColumnSeries3D.AdornmentsInfo>
</chart:ColumnSeries3D >
<chart:ColumnSeries3D XBindingPath="FruitName"
YBindingPath="People2"
SeriesSelectionBrush="Blue"
ItemsSource="{Binding Fruits}">
<chart:ColumnSeries3D.AdornmentsInfo>
<chart:ChartAdornmentInfo3D AdornmentsPosition="TopAndBottom"
ShowLabel="true"
HighlightOnSelection="True"/>
</chart:ColumnSeries3D.AdornmentsInfo>
</chart:ColumnSeries3D >
</chart:SfChart3D >
The following screenshot is an example of a SfChart3D
with series selection.
Dynamic explode
This feature allows users to explode a particular segment in a circular series using ExplodeOnMouseClick
. This can also be achieved by setting the ExplodeIndex
or ExplodeAll
property.
The following code example illustrates how to enable dynamic explode for circular series, for data please refer series category in 3D charts.
<Syncfusion:SfChart3D EnableRotation="True" x:Name="Chart" Height="500" Width="600">
<Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:CategoryAxis3D/>
</Syncfusion:SfChart3D.PrimaryAxis>
<Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:NumericalAxis3D/>
</Syncfusion:SfChart3D.SecondaryAxis>
<Syncfusion:PieSeries3D
ExplodeOnMouseClick="True"
ItemsSource="{Binding UsersList}"
XBindingPath="TimeStamp"
YBindingPath="NoOfUsers">
</Syncfusion:PieSeries3D>
</Syncfusion:SfChart3D >
The following image illustrates the result of the above code sample: