R
R
RommB2021-03-29 21:01:14
C++ / C#
RommB, 2021-03-29 21:01:14

How to draw a line chart in Windows Forms c#?

I don’t understand how to arrange it: Draw a line chart, putting each matrix in accordance with a separate data series. On the abscissa axis, you need to put natural numbers from 1 to M, and on the ordinate axis - the number of matrix elements, which include at least k digits, are repeated, where k is the abscissa of the graph point, M is the maximum number of digits, are repeated.

Here is my code:

public partial class ChartForm : Form
    {
        int[,] matrix1;
        int[,] matrix2;


        public ChartForm(int[,] matrix1, int[,] matrix2)
        {
            this.matrix1 = matrix1;
            this.matrix2 = matrix2;
            InitializeComponent();
        }
        private void ChartForm_Load(object sender, EventArgs e)
        {
            chart1.Series.Clear();
            AddSeries(matrix1, "Matrix 1");
            AddSeries(matrix2, "Matrix 2");
        }

        void AddSeries(int[,] matrix, string name)
        {
            var series = new Series { ChartType = SeriesChartType.Column, Name = name };
            var set = new HashSet<int>();
            for (int i = 1; i < matrix.GetLength(0); i++)
            {
                set.Clear();
                for(int j = 1; j < matrix.GetLength(1); j++)
                {
                    set.Add(matrix[i, j]);
                }
                series.Points.Add(set.Count);
            }
            chart1.Series.Add(series);
        }
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question