This example shows data being displayed on a polar chart. Polar charts are useful when plotting circular phenomena.
The radial axis measures the incident angle of the sound and the other axis measures the decibels of sound the microphone picks up. Different microphones have different directional profiles.
Note that this example uses data from an external data source not included in the code snippets - download the examples source code in full to view the data.
XAML + CODE +
<UserControl x:Class="Visiblox.Charts.Examples.PolarChart.PolarChartExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:charts="clr-namespace:Visiblox.Charts;assembly=Visiblox.Charts"
xmlns:local="clr-namespace:Visiblox.Charts.Examples.PolarChart"
mc:Ignorable="d">
<UserControl.Resources>
<Style x:Key="LegendNoBorder" TargetType="charts:Legend">
<Setter Property="BorderThickness" Value="0"/>
</Style>
<Style x:Key="LabelStyle" TargetType="TextBlock">
<Setter Property="FontSize" Value="13"/>
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition Height="350" />
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<!-- Ultimate Trial users should add 'ValidationKey="ENTER TRIAL LICENSE KEY HERE"' to each Chart declaration. -->
<charts:RadialChart Name="PolarChart" DrawingMode="Circular" Width="600" LegendStyle="{StaticResource LegendNoBorder}"
Grid.Row="0" Title="Comparing Microphone Polar Patterns" HorizontalAlignment="Center" LegendPosition="OutsideMiddleRight"
XLabelsDistance="14">
<charts:RadialChart.XAxis>
<charts:RadialLinearAxis LabelFormatString="{}0°" LabelStyle="{StaticResource LabelStyle}" >
<charts:RadialLinearAxis.Range>
<charts:DoubleRange Maximum="360" Minimum="0" />
</charts:RadialLinearAxis.Range>
</charts:RadialLinearAxis>
</charts:RadialChart.XAxis>
<charts:RadialChart.YAxis>
<charts:RadialLinearAxis LabelFormatString="{}0dB" LabelStyle="{StaticResource LabelStyle}">
<charts:RadialLinearAxis.Range>
<charts:DoubleRange Maximum="10" Minimum="0" />
</charts:RadialLinearAxis.Range>
</charts:RadialLinearAxis>
</charts:RadialChart.YAxis>
</charts:RadialChart>
<!-- Set up an area to display the selected item's microphone info -->
<Border BorderBrush="LightGray" Grid.Row="1" Width="600" Height="150" BorderThickness="1" CornerRadius="5"
Background="White" Padding="3,1" HorizontalAlignment="Left" VerticalAlignment="Top">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="50" />
<RowDefinition Height="70" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal">
<TextBlock FontWeight="Bold" Name="MicrophoneTitle" Text="Microphone Title" />
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Vertical">
<TextBlock FontStyle="Italic" Name="MicrophoneDescription" Text="Please select a chart series to get more information on the microphone polar pattern."
Width="590" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Left" />
</StackPanel>
<Grid Grid.Row="2" VerticalAlignment="Bottom">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Coverage Angle:" />
<TextBlock Grid.Row="0" Grid.Column="1" Name="CoverageAngle" />
<TextBlock Grid.Row="1" Grid.Column="0" Text="Angle Of Maximum Rejection (null angle):" />
<TextBlock Grid.Row="1" Grid.Column="1" Name="AngleOfMaximumRejection" />
<TextBlock Grid.Row="2" Grid.Column="0" Text="Ambient Sound Sensitivity (relative to omni):" />
<TextBlock Grid.Row="2" Grid.Column="1" Name="AmbientSoundSensitivity" />
<TextBlock Grid.Row="3" Grid.Column="0" Text="Distance Factor (relative to omni):" />
<TextBlock Grid.Row="3" Grid.Column="1" Name="DistanceFactor" />
</Grid>
</Grid>
</Border>
</Grid>
</UserControl>
^ Back To Top
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Windows.Controls;
namespace Visiblox.Charts.Examples.PolarChart
{
/// <summary>
/// An example to demonstrate Visiblox radial chart capabilities
/// </summary>
public partial class PolarChartExample : UserControl
{
public PolarChartExample()
{
InitializeComponent();
PolarChart.Series = new RadialSeriesCollection();
foreach (MicrophoneInfo microphone in GetMicrophoneData())
{
RadialLineSeries radialLineSeries = new RadialLineSeries();
radialLineSeries.HighlightingEnabled = true;
radialLineSeries.SelectionMode = SelectionMode.Series;
radialLineSeries.PropertyChanged += new PropertyChangedEventHandler(RadialLineSeries_PropertyChanged);
radialLineSeries.DataSeries = microphone.Data;
radialLineSeries.Tag = microphone;
PolarChart.Series.Add(radialLineSeries);
}
}
private void RadialLineSeries_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
RadialLineSeries selectedSeries = sender as RadialLineSeries;
if (e.PropertyName == "IsSelected")
{
ClearDetailsBlock();
if (selectedSeries.IsSelected)
{
//Unselect the other series except for the one that just got selected
UnselectAllOtherSeries(selectedSeries);
ChangeDetailsBlock(selectedSeries.Tag as MicrophoneInfo);
}
}
}
/// <summary>
/// Print the selected microphone's details
/// </summary>
private void ChangeDetailsBlock(MicrophoneInfo microphone)
{
MicrophoneTitle.Text = microphone.Title;
MicrophoneDescription.Text = microphone.Description;
CoverageAngle.Text = microphone.CoverageAngle;
AngleOfMaximumRejection.Text = microphone.AngleOfMaximumRejection;
AmbientSoundSensitivity.Text = microphone.AmbientSoundSensitivity;
DistanceFactor.Text = microphone.DistanceFactor;
}
/// <summary>
/// Clear the details block
/// </summary>
private void ClearDetailsBlock()
{
MicrophoneTitle.Text = "Microphone Title";
MicrophoneDescription.Text = "Please select a chart series to get more information on the microphone polar pattern.";
CoverageAngle.Text = string.Empty;
AngleOfMaximumRejection.Text = string.Empty;
AmbientSoundSensitivity.Text = string.Empty;
DistanceFactor.Text = string.Empty;
}
/// <summary>
/// Unselect all the series except the selected one so that only one series is selected at a time
/// </summary>
/// <returns>Return the data for the selected series</returns>
private void UnselectAllOtherSeries(RadialLineSeries selectedSeries)
{
foreach (RadialLineSeries lineSeries in PolarChart.Series)
{
if (lineSeries != selectedSeries)
lineSeries.IsSelected = false;
}
}
/// <summary>
/// Read the data from the csv file
/// </summary>
private IEnumerable<MicrophoneInfo> GetMicrophoneData()
{
var results = new List<MicrophoneInfo>();
//Create the first microphone and add it to the collection
MicrophoneInfo microphone = new MicrophoneInfo();
microphone.Data = new DataSeries<double, double>();
results.Add(microphone);
using (StreamReader reader = new StreamReader(ExampleHelpers.GetApplicationResourceStream("PolarChart/Data/MPP.csv").Stream))
{
while (reader.Peek() >= 0)
{
string line = reader.ReadLine();
if (line.Length == 0)
{
//When we reach here, a microphone already exists in the collection
microphone = new MicrophoneInfo();
microphone.Data = new DataSeries<double, double>();
results.Add(microphone);
}
else
{
string[] values = line.Split('|');
if (values[0] == "Description")
microphone.Description = values[1];
else if (values[0] == "CoverageAngle")
microphone.CoverageAngle = values[1];
else if (values[0] == "AngleOfMaximumRejection")
microphone.AngleOfMaximumRejection = values[1];
else if (values[0] == "AmbientSoundSensitivity")
microphone.AmbientSoundSensitivity = values[1];
else if (values[0] == "DistanceFactor")
microphone.DistanceFactor = values[1];
else if (values[0] == "Title")
{
microphone.Title = values[1];
microphone.Data.Title = values[1];
}
else
{
double degree = double.Parse(values[0]);
double decibels = double.Parse(values[1]);
microphone.Data.Add(degree, decibels);
}
}
}
}
return results;
}
}
// Data Model
public class MicrophoneInfo
{
public string Title { get; set; }
public string Description { get; set; }
public string CoverageAngle { get; set; }
public string AngleOfMaximumRejection { get; set; }
public string AmbientSoundSensitivity { get; set; }
public string DistanceFactor { get; set; }
public DataSeries<double, double> Data { get; set; }
}
}
^ Back To Top

