43 lines
1.5 KiB
C#
43 lines
1.5 KiB
C#
///
|
|
/// Copyright (c) 2019 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using System.Windows.Forms.DataVisualization.Charting;
|
|
|
|
namespace ResultsBrowser.Forms
|
|
{
|
|
public partial class HistogramCtrl : UserControl
|
|
{
|
|
/// <summary>
|
|
/// Create user control that displays a bar chart iwth custom X-axis labels.
|
|
/// </summary>
|
|
/// <param name="title">Title of the chart displayed at the top</param>
|
|
/// <param name="values">Values = bar lengths</param>
|
|
/// <param name="labels">Labels for the X-axis</param>
|
|
public HistogramCtrl(string title, double[] values, string[] labels)
|
|
{
|
|
InitializeComponent();
|
|
|
|
if (myChart.Titles.Count > 0) myChart.Titles[0].Text = title;
|
|
|
|
if ((myChart.Series.Count > 0) && (values != null))
|
|
{
|
|
int startOffset = -1;
|
|
int endOffset = 1;
|
|
for (int i = 0; i < Math.Min(values.Length + 1, labels.Length); i++)
|
|
{
|
|
if (i < values.Length) myChart.Series[0].Points.Add(values[i]);
|
|
if (!string.IsNullOrEmpty(labels[i]))
|
|
{
|
|
myChart.ChartAreas[0].AxisX.CustomLabels.Add(new System.Windows.Forms.DataVisualization.Charting.CustomLabel(startOffset, endOffset, labels[i], 0, LabelMarkStyle.None));
|
|
}
|
|
startOffset = startOffset + 1;
|
|
endOffset = endOffset + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|