SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
Please note! These examples are new to SciChart Mobile v3 release! SciChart iOS & Android ship with Xamarin.iOS and Xamarin.Android bindings around our native iOS & Android Chart controls, allowing you to create fast & feature rich charts to your Xamarin applications. We include ~90 native iOS examples and 90 Android examples, but now also ~60 Xamarin Chart Examples to help you get started with SciChart. You can download the source for our Xamarin Chart Examples from Github, or browse the source code below.
This example demonstrates how Camera 3D works in SciChart with Xamarin. It shows how different properties define the view port as seen by the camera
Learn more from the documentation about Camera 3D: SciChart Surface and Camera 3D in Android SciChart Surface and Camera 3D in iOS
The C#/Xamarin.iOS/Xamarin.Android source code for the Modify Camera3D Properties example is included below (Scroll down!).
Did you know you can also view the source code from one of the following sources as well?
using SciChart.iOS.Charting;
namespace Xamarin.Examples.Demo.iOS
{
[Example3DDefinition("Modify Camera3D Properties", description: "Demonstrates the properties of the Camera3D", icon: ExampleIcon.ZoomPan)]
class ModifyCamera3DPropertiesViewController : CustomLayoutViewController<ModifyCamera3DPropertiesLayout>
{
public SCIChartSurface3D Surface => Layout.SurfaceView;
protected override void CommonInit()
{
Layout.Pitch.ValueChanged += (sender, args) => Surface.Camera.OrbitalPitch = Layout.Pitch.Value;
Layout.Yaw.ValueChanged += (sender, args) => Surface.Camera.OrbitalYaw= Layout.Yaw.Value;
Layout.Radius.ValueChanged += (sender, args) => Surface.Camera.Radius = Layout.Radius.Value;
Layout.FOV.ValueChanged += (sender, args) => Surface.Camera.FieldOfView= Layout.FOV.Value;
Layout.Height.ValueChanged += (sender, args) => Surface.Camera.OrthoHeight = Layout.Height.Value;
Layout.Width.ValueChanged += (sender, args) => Surface.Camera.OrthoWidth = Layout.Width.Value;
Layout.Projection.ValueChanged += (sender, args) =>
{
if (Layout.Projection.SelectedSegment == 0)
{
Surface.Camera.ToPerspective();
}
else
{
Surface.Camera.ToOrhtogonal();
}
Layout.UpdateWithIsPerspective(Layout.Projection.SelectedSegment == 0);
};
Layout.Coordinates.ValueChanged += (sender, args) => Surface.Viewport.IsLeftHandedCoordinateSystem = Layout.Coordinates.SelectedSegment == 0;
Layout.UpdateWithIsPerspective(true);
}
protected override void InitExample()
{
using (Surface.SuspendUpdates())
{
Surface.XAxis = new SCINumericAxis3D();
Surface.YAxis = new SCINumericAxis3D();
Surface.ZAxis = new SCINumericAxis3D();
Surface.ChartModifiers.Add(CreateDefault3DModifiers());
Surface.Camera = new SCICamera3D();
Surface.Camera.SetCameraUpdateListener(Layout);
}
}
}
}
using Android.Views;
using Android.Widget;
using SciChart.Charting3D.Model;
using SciChart.Charting3D.Modifiers;
using SciChart.Charting3D.Visuals;
using SciChart.Charting3D.Visuals.Axes;
using SciChart.Charting3D.Visuals.Camera;
using Xamarin.Examples.Demo;
using System;
using Xamarin.Examples.Demo.Droid.Fragments.Base;
namespace Xamarin.Examples.Demo.Droid.Fragments.Examples3D
{
[Example3DDefinition("Modify Camera3D Properties", description: "Demonstrates the properties of the Camera3D", icon: ExampleIcon.ZoomPan)]
class ModifyCamera3DPropertiesFragment : ExampleBaseFragment, ICameraUpdateListener
{
public SciChartSurface3D Surface => View.FindViewById<SciChartSurface3D>(Resource.Id.chart3d);
public override int ExampleLayoutId => Resource.Layout.Example_Chart3D_Camera_Properies_Fragment;
private TextView Position => View.FindViewById<TextView>(Resource.Id.positionText);
private SeekBar Yaw => View.FindViewById<SeekBar>(Resource.Id.yawSeekBar);
private SeekBar Pitch => View.FindViewById<SeekBar>(Resource.Id.pitchSeekBar);
private SeekBar Radius => View.FindViewById<SeekBar>(Resource.Id.radiusSeekBar);
private SeekBar Fov => View.FindViewById<SeekBar>(Resource.Id.fovSeekBar);
private SeekBar OrthoWidth => View.FindViewById<SeekBar>(Resource.Id.orthoWidthSeekBar);
private SeekBar OrthoHeight => View.FindViewById<SeekBar>(Resource.Id.orthoHeightSeekBar);
private LinearLayout PerspectiveLayout => View.FindViewById<LinearLayout>(Resource.Id.perspectiveProperties);
private LinearLayout OrthogonalLayout => View.FindViewById<LinearLayout>(Resource.Id.orthogonalProperties);
protected override void InitExample()
{
SetUpUi();
using (Surface.SuspendUpdates())
{
Surface.XAxis = new NumericAxis3D();
Surface.YAxis = new NumericAxis3D();
Surface.ZAxis = new NumericAxis3D();
Surface.Camera = new Camera3D();
Surface.Camera.SetCameraUpdateListener(this);
Surface.ChartModifiers = new ChartModifier3DCollection
{
new PinchZoomModifier3D(),
new OrbitModifier3D(),
new ZoomExtentsModifier3D()
};
}
}
private void SetUpUi()
{
Pitch.ProgressChanged += (s, e) =>
{
Surface.Camera.OrbitalPitch = e.Progress;
};
Yaw.ProgressChanged += (s, e) =>
{
Surface.Camera.OrbitalYaw = e.Progress;
};
Radius.ProgressChanged += (s, e) =>
{
Surface.Camera.Radius = e.Progress;
};
Fov.ProgressChanged += (s, e) =>
{
Surface.Camera.FieldOfView = e.Progress;
};
OrthoWidth.ProgressChanged += (s, e) =>
{
Surface.Camera.OrthoWidth = e.Progress;
};
OrthoHeight.ProgressChanged += (s, e) =>
{
Surface.Camera.OrthoHeight = e.Progress;
};
View.FindViewById<Button>(Resource.Id.lhsRadioButton).Click += (s, e) =>
{
Surface.IsLeftHandedCoordinateSystem = true;
};
View.FindViewById<Button>(Resource.Id.rhsRadioButton).Click += (s, e) =>
{
Surface.IsLeftHandedCoordinateSystem = false;
};
View.FindViewById<Button>(Resource.Id.perspectiveRadioButton).Click += (s, e) =>
{
Surface.Camera.ToPerspective();
PerspectiveLayout.Visibility = ViewStates.Visible;
OrthogonalLayout.Visibility = ViewStates.Gone;
};
View.FindViewById<Button>(Resource.Id.orthogonalRadioButton).Click += (s, e) =>
{
Surface.Camera.ToOrthogonal();
PerspectiveLayout.Visibility = ViewStates.Gone;
OrthogonalLayout.Visibility = ViewStates.Visible;
};
OrthogonalLayout.Visibility = ViewStates.Gone;
UpdateUIWithValuesFrom(Surface.Camera);
}
public void OnCameraUpdated(ICameraController camera)
{
Surface.Camera.OrbitalPitch = ConstrainAngle(Surface.Camera.OrbitalPitch);
Surface.Camera.OrbitalYaw = ConstrainAngle(Surface.Camera.OrbitalYaw);
Activity.RunOnUiThread(() => {
UpdateUIWithValuesFrom(camera);
});
}
private static float ConstrainAngle(float angle)
{
if (angle < 0)
{
angle += 360;
}
else if (angle > 360)
{
angle -= 360;
}
return angle;
}
private void UpdateUIWithValuesFrom(ICameraController camera)
{
var pos = camera.Position;
Position.Text = $"Position: X={pos.GetX():0.0}, Y={pos.GetY():0.0}, Z={pos.GetZ():0.0}";
TrySetSeekBarProgress(Pitch, camera.OrbitalPitch);
TrySetSeekBarProgress(Yaw, camera.OrbitalYaw);
TrySetSeekBarProgress(Radius, camera.Radius);
TrySetSeekBarProgress(Fov, camera.FieldOfView);
TrySetSeekBarProgress(OrthoWidth, camera.OrthoWidth);
TrySetSeekBarProgress(OrthoHeight, camera.OrthoHeight);
}
private void TrySetSeekBarProgress(SeekBar seekBar, float value)
{
var progress = (int)Math.Round(value);
if(seekBar.Progress != progress)
{
seekBar.Progress = progress;
}
}
}
}