Reputation: 93
Somewhere in internet I found this code
private void PopulateChart()
{
int elements = 500;
Random r = new Random();
List<double> xValues = new List<double>();
double currentX = 0;
for (int i = 0; i < elements; i++)
{
xValues.Add(currentX);
currentX = currentX + r.Next(1, 2000);
}
List<double> yValues = new List<double>();
for (int i = 0; i < elements; i++)
{
yValues.Add(r.Next(0, 50));
}
// remove all previous series
chart1.Series.Clear();
var series = chart1.Series.Add("MySeries");
series.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Stock;
//series.XValueType = System.Windows.Forms.DataVisualization.Charting.ChartValueType.Auto;
DateTime baseDate = DateTime.Today;
for (int i = 0; i < xValues.Count; i++)
{
var xDate = baseDate.AddSeconds(xValues[i]);
var yValue = yValues[i];
series.Points.AddXY(xDate, yValue);
}
// show an X label every itme interval (values in minute 60 = 1 hour)
chart1.ChartAreas[series.ChartArea].AxisX.Interval = 100.0;
chart1.ChartAreas[0].AxisX.IntervalType = System.Windows.Forms.DataVisualization.Charting.DateTimeIntervalType.Minutes;
// label format
chart1.ChartAreas[0].AxisX.LabelStyle.Format = "HH:mm:ss";
}
This displays random data in chart with grouping of data with some time interval. Now I want to put a horizontal scrollbar (x-axis). I tried using code used in this post
Adding a scroll bar to MS Chart control C#
but I couldnot apply it with full functionality. Can anyone help me in this problem?
Upvotes: 2
Views: 7259
Reputation: 493
You have enable the X axis for zooming.
chart1.ChartAreas["ChartArea1"].CursorX.IsUserEnabled = true;
chart1.ChartAreas["ChartArea1"].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas["ChartArea1"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["ChartArea1"].AxisX.ScrollBar.IsPositionedInside = true;
Upvotes: 5