0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[WinForms] 3Dチャート

Posted at
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

using OpenCvSharp;

namespace ChartingApp
{
    public partial class Form1 : Form
    {
        Chart chart;
        public Form1()
        {
            InitializeComponent();

            var image = new Mat("data.bmp", ImreadModes.Grayscale);
            image = image.Resize(new OpenCvSharp.Size(image.Cols / 30, image.Rows / 30));
            image = image.Normalize(0, 255, NormTypes.MinMax);

            this.Width = 1000;
            this.Height = 800;

            TrackBar track = new TrackBar();
            track.Dock = DockStyle.Bottom;
            track.Minimum = -44;
            track.Maximum = 44;
            track.LargeChange = 50;
            track.SmallChange = 50;
            track.Value = 30;
            this.Controls.Add(track);

            TrackBar track2 = new TrackBar();
            track2.Dock = DockStyle.Top;
            track2.Minimum = -90;
            track2.Maximum = 90;
            track2.LargeChange = 1;
            track2.SmallChange = 1;
            track2.Value = 15;
            this.Controls.Add(track2);

            TrackBar track3 = new TrackBar();
            track3.Dock = DockStyle.Bottom;
            track3.Minimum = 0;
            track3.Maximum = 100;
            track3.LargeChange = 1;
            track3.SmallChange = 1;
            track3.Value = 30;
            this.Controls.Add(track3);

            ChartArea area = new ChartArea();

            area.AxisX.Title = "X";
            area.AxisX.Minimum = -10;
            area.AxisX.Maximum = image.Cols + 10;
            area.AxisX.Interval = 20;

            area.AxisY.Title = "Y";
            area.AxisY.Minimum = -10;
            area.AxisY.Maximum = 255 + 50;
            area.AxisY.Interval = 20;

            var style = area.Area3DStyle;
            style.Enable3D = true;
            style.IsRightAngleAxes = true;
            style.Perspective = 20;
            style.Rotation = track.Value;
            style.Inclination = track2.Value;
            style.Perspective = track3.Value;

            chart = new Chart();
            chart.ChartAreas.Add(area);

            Random rnd = new Random();
            for (int i = 0; i < image.Rows; i++)
            {
                var series = new Series();
                series.ChartType = SeriesChartType.Point;
                series.MarkerSize = 5;
                series.MarkerStyle = MarkerStyle.Circle;
                series.BorderColor = Color.Tomato;
                //series.Color = Color.Tomato;
                chart.Series.Add(series);

                for (int x = 0; x <= image.Cols; x++)
                {
                    var value = image.At<byte>(i, x);
                    series.Points.AddXY(x, value);
                }
            }

            area.Position = new ElementPosition(0f, 0f, 100f, 90f);
            chart.Dock = DockStyle.Fill;
            this.Controls.Add(chart);

            track.ValueChanged += (s, e) =>
            {
                this.chart.ChartAreas[0].Area3DStyle.Rotation = ((TrackBar)s).Value;
            };
            track2.ValueChanged += (s, e) =>
            {
                this.chart.ChartAreas[0].Area3DStyle.Inclination = ((TrackBar)s).Value;
            };
            track3.ValueChanged += (s, e) =>
            {
                this.chart.ChartAreas[0].Area3DStyle.Perspective = ((TrackBar)s).Value;
            };
        }
    }
}

image.png

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?