Back to Devexpress

Scatter Polar Line Chart

windowsforms-113900-controls-and-libraries-chart-control-series-views-2d-series-views-polar-series-views-scatter-polar-line-chart.md

latest18.2 KB
Original Source

Scatter Polar Line Chart

  • Oct 02, 2023
  • 7 minutes to read

The Scatter Polar Line chart uses the ScatterPolarLineSeriesView to visualize data. The Chart Control displays series points in the same order they were added to the collection without aggregation by arguments.

The following image shows a Scatter Polar Line Chart (the Archimedean spiral):

Run Demo: Polar Views

Chart Type Characteristics

The table below lists the main Scatter Polar Line chart characteristics:

FeatureValue
Series View typeScatterPolarLineSeriesView
Diagram type2D-PolarDiagram
Number of arguments per series point1
Number of values per series point1

Note

  • For information on which chart types can be combined with the Scatter Polar Line chart, refer to the Series Views Compatibility document.
  • The axis scale types should be numeric continuous to display data correctly.

Create a Scatter Polar Line Chart at Runtime

Add Points Manually

The following example creates a Scatter Polar Line Chart at runtime:

csharp
using DevExpress.XtraCharts;
using System;
using System.Windows.Forms;
using DevExpress.Utils;

namespace ScatterPolarLine {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            // Create a new chart.
            ChartControl scatterPolarLineChart = new ChartControl();

            // Add the chart to the form.
            scatterPolarLineChart.Dock = DockStyle.Fill;
            this.Controls.Add(scatterPolarLineChart);

            // Create a scatter polar line series.
            Series series1 = new Series("Series 1", ViewType.ScatterPolarLine);

            // Add points to it.
            series1.Points.Add(new SeriesPoint(0, 0.523598));
            series1.Points.Add(new SeriesPoint(30, 0.523598));
            series1.Points.Add(new SeriesPoint(60, 1.047197));
            series1.Points.Add(new SeriesPoint(90, 1.570796));
            series1.Points.Add(new SeriesPoint(120, 2.094395));
            series1.Points.Add(new SeriesPoint(150, 2.617993));
            series1.Points.Add(new SeriesPoint(180, 3.141592));
            series1.Points.Add(new SeriesPoint(210, 3.665191));
            series1.Points.Add(new SeriesPoint(240, 4.188790));
            series1.Points.Add(new SeriesPoint(270, 4.712388));
            series1.Points.Add(new SeriesPoint(300, 5.235987));
            series1.Points.Add(new SeriesPoint(330, 5.759586));
            series1.Points.Add(new SeriesPoint(0, 6.283185));
            series1.Points.Add(new SeriesPoint(30, 6.806784));
            series1.Points.Add(new SeriesPoint(60, 7.330382));
            series1.Points.Add(new SeriesPoint(90, 7.853981));
            series1.Points.Add(new SeriesPoint(120, 8.377580));
            series1.Points.Add(new SeriesPoint(150, 8.901179));
            series1.Points.Add(new SeriesPoint(180, 9.424777));
            series1.Points.Add(new SeriesPoint(210, 9.948376));
            series1.Points.Add(new SeriesPoint(240, 10.4719755));
            series1.Points.Add(new SeriesPoint(270, 10.9955742));
            series1.Points.Add(new SeriesPoint(300, 11.5191730));
            series1.Points.Add(new SeriesPoint(330, 12.04277183));
            series1.Points.Add(new SeriesPoint(0, 12.56637061));

            // Add the series to the chart.
            scatterPolarLineChart.Series.Add(series1);

            // Flip the diagram (if necessary).
            ((PolarDiagram)scatterPolarLineChart.Diagram).StartAngleInDegrees = 180;
            ((PolarDiagram)scatterPolarLineChart.Diagram).RotationDirection =
                RadarDiagramRotationDirection.Counterclockwise;

            // Hide the legend (if necessary).
            scatterPolarLineChart.Legend.Visibility = DefaultBoolean.False;

            // Add a title to the chart (if necessary).
            scatterPolarLineChart.Titles.Add(new ChartTitle());
            scatterPolarLineChart.Titles[0].Text = "A Scatter Polar Line Chart";
        }
    }
}
vb
Imports DevExpress.XtraCharts
Imports System
Imports System.Windows.Forms
Imports DevExpress.Utils

Namespace ScatterPolarLine
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
            ' Create a new chart.
            Dim scatterPolarLineChart As New ChartControl()

            ' Add the chart to the form.
            scatterPolarLineChart.Dock = DockStyle.Fill
            Me.Controls.Add(scatterPolarLineChart)

            ' Create a scatter polar line series.
            Dim series1 As New Series("Series 1", ViewType.ScatterPolarLine)

            ' Add points to it.
            series1.Points.Add(New SeriesPoint(0, 0.523598))
            series1.Points.Add(New SeriesPoint(30, 0.523598))
            series1.Points.Add(New SeriesPoint(60, 1.047197))
            series1.Points.Add(New SeriesPoint(90, 1.570796))
            series1.Points.Add(New SeriesPoint(120, 2.094395))
            series1.Points.Add(New SeriesPoint(150, 2.617993))
            series1.Points.Add(New SeriesPoint(180, 3.141592))
            series1.Points.Add(New SeriesPoint(210, 3.665191))
            series1.Points.Add(New SeriesPoint(240, 4.188790))
            series1.Points.Add(New SeriesPoint(270, 4.712388))
            series1.Points.Add(New SeriesPoint(300, 5.235987))
            series1.Points.Add(New SeriesPoint(330, 5.759586))
            series1.Points.Add(New SeriesPoint(0, 6.283185))
            series1.Points.Add(New SeriesPoint(30, 6.806784))
            series1.Points.Add(New SeriesPoint(60, 7.330382))
            series1.Points.Add(New SeriesPoint(90, 7.853981))
            series1.Points.Add(New SeriesPoint(120, 8.377580))
            series1.Points.Add(New SeriesPoint(150, 8.901179))
            series1.Points.Add(New SeriesPoint(180, 9.424777))
            series1.Points.Add(New SeriesPoint(210, 9.948376))
            series1.Points.Add(New SeriesPoint(240, 10.4719755))
            series1.Points.Add(New SeriesPoint(270, 10.9955742))
            series1.Points.Add(New SeriesPoint(300, 11.5191730))
            series1.Points.Add(New SeriesPoint(330, 12.04277183))
            series1.Points.Add(New SeriesPoint(0, 12.56637061))

            ' Add the series to the chart.
            scatterPolarLineChart.Series.Add(series1)

            ' Flip the diagram (if necessary).
            CType(scatterPolarLineChart.Diagram, PolarDiagram).StartAngleInDegrees = 180
            CType(scatterPolarLineChart.Diagram, PolarDiagram).RotationDirection = RadarDiagramRotationDirection.Counterclockwise

            ' Hide the legend (if necessary).
            scatterPolarLineChart.Legend.Visibility = DefaultBoolean.False

            ' Add a title to the chart (if necessary).
            scatterPolarLineChart.Titles.Add(New ChartTitle())
            scatterPolarLineChart.Titles(0).Text = "A Scatter Polar Line Chart"
        End Sub
    End Class
End Namespace

Result:

Bind a Chart to a Data Source

The following example binds a Scatter Polar Line Chart to a data table:

csharp
private void Form1_Load(object sender, EventArgs e) {
    // Create a new chart.
    ChartControl scatterPolarLineChart = new ChartControl();

    // Add the chart to the form.
    scatterPolarLineChart.Dock = DockStyle.Fill;
    this.Controls.Add(scatterPolarLineChart);
    scatterPolarLineChart.DataSource = CreateChartData();

    // Create a scatter polar line series.
    Series series = new Series("Series 1", ViewType.ScatterPolarLine);
    series.ArgumentDataMember = "Angle";
    series.ValueDataMembers.AddRange(new string[] { "Distance" });
    scatterPolarLineChart.Series.Add(series);
    ScatterPolarLineSeriesView view = (ScatterPolarLineSeriesView)series.View;

    // Hide markers.
    view.MarkerVisibility = DefaultBoolean.False;
    // Hide the line that connects the first and last point.
    view.Closed = false;

    // Hide the legend.
    scatterPolarLineChart.Legend.Visibility = DefaultBoolean.False;

    // Add a title to the chart.
    scatterPolarLineChart.Titles.Add(new ChartTitle());
    scatterPolarLineChart.Titles[0].Text = "Archimedean Spiral";
}

private DataTable CreateChartData() {
    DataTable table = new DataTable("Table1");
    table.Columns.Add("Angle", typeof(double));
    table.Columns.Add("Distance", typeof(double));

    double minAngle = 0;
    double maxAngle = 720;
    int intervalsCount = 72;
    double angleStep = (maxAngle - minAngle) / (double)intervalsCount;
    for (int pointIndex = 0; pointIndex <= intervalsCount; pointIndex++) {
        double angle = minAngle + pointIndex * angleStep;
        double angleRadians = angle * Math.PI / 180.0;
        double distance = angleRadians;
        double normalizeAngle = angle % 360;
        table.Rows.Add(new object[] { normalizeAngle, distance });
    }
    return table;
}
vb
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
    ' Create a new chart.
    Dim scatterPolarLineChart As ChartControl = New ChartControl()

    ' Add the chart to the form.
    scatterPolarLineChart.Dock = DockStyle.Fill
    Me.Controls.Add(scatterPolarLineChart)
    scatterPolarLineChart.DataSource = CreateChartData()

    ' Create a scatter polar line series.
    Dim series As Series = New Series("Series 1", ViewType.ScatterPolarLine)
    series.ArgumentDataMember = "Angle"
    series.ValueDataMembers.AddRange(New String() {"Distance"})
    scatterPolarLineChart.Series.Add(series)
    Dim view As ScatterPolarLineSeriesView = CType(series.View, ScatterPolarLineSeriesView)

    ' Hide markers.
    view.MarkerVisibility = DefaultBoolean.[False]
    ' Hide the line that connects the first and last point.
    view.Closed = False

    ' Hide the legend.
    scatterPolarLineChart.Legend.Visibility = DefaultBoolean.[False]

    ' Add a title to the chart.
    scatterPolarLineChart.Titles.Add(New ChartTitle())
    scatterPolarLineChart.Titles(0).Text = "Archimedean Spiral"
End Sub

Private Function CreateChartData() As DataTable
    Dim table As DataTable = New DataTable("Table1")
    table.Columns.Add("Angle", GetType(Double))
    table.Columns.Add("Distance", GetType(Double))
    Dim minAngle As Double = 0
    Dim maxAngle As Double = 720
    Dim intervalsCount As Integer = 72
    Dim angleStep As Double = (maxAngle - minAngle) / intervalsCount

    For pointIndex As Integer = 0 To intervalsCount
        Dim angle As Double = minAngle + pointIndex * angleStep
        Dim angleRadians As Double = angle * Math.PI / 180.0
        Dim distance As Double = angleRadians
        Dim normalizeAngle As Double = angle Mod 360
        table.Rows.Add(New Object() {normalizeAngle, distance})
    Next

    Return table
End Function

Result:

Change Chart Appearance

The ScatterPolarLineSeriesView class exposes the following appearance settings for the Scatter Polar Line chart:

The code below changes the marker border color, line color and thickness, and displays the line shadow:

csharp
using DevExpress.Utils;
using System.Drawing;
//...
ScatterPolarLineSeriesView view = (ScatterPolarLineSeriesView)series1.View;
view.LineMarkerOptions.BorderColor = Color.DarkBlue;
view.LineStyle.Thickness = 3;
view.Color = Color.CornflowerBlue;
view.Shadow.Color = Color.LightGray;
view.Shadow.Visible = true;
view.Closed = false;
vb
Imports DevExpress.Utils
Imports System.Drawing
'...
Dim view As ScatterPolarLineSeriesView = CType(series1.View, ScatterPolarLineSeriesView)
view.LineMarkerOptions.BorderColor = Color.DarkBlue
view.LineStyle.Thickness = 3
view.Color = Color.CornflowerBlue
view.Shadow.Color = Color.LightGray
view.Shadow.Visible = True
view.Closed = False

Tip

You can use tooltips to show additional information when a user hovers a series point. Note the Chart Control does not display Crosshair Cursor for polar and radar series.

See Also

Polar Series Views

Lesson 3 - Bind Chart Series to Data