차트에 플롯 된 간단한 그래프가 있습니다. X 축에서 값은 DateTime
값입니다.날짜/시간 x 축 차트에서 부드러운 스 크롤
public partial class Form1 : Form
{
List<double> valuelist = new List<double>();
List<DateTime> timelist = new List<DateTime>();
public Form1()
{
InitializeComponent();
// fill the lists with values
for (int i = 0; i < 2000; i++)
{
double value = Math.Sin(i/20.0);
valuelist.Add(value);
timelist.Add(DateTime.Now.AddMinutes(i + 2));
}
// add the Values to the chart
for (int i = 0; i < valuelist.Count; i++)
{
this.chart1.Series[0].Points.AddXY(timelist[i], valuelist[i]);
}
this.chart1.ChartAreas[0].AxisX.LabelStyle.Format = "dd.MM-hh:mm";
}
private void Form1_Load(object sender, EventArgs e)
{
chart1.Series[0].XValueType = ChartValueType.DateTime;
chart1.ChartAreas[0].AxisX.Maximum = timelist.Max().ToOADate();
chart1.ChartAreas[0].AxisX.Minimum = timelist.Min().ToOADate();
chart1.ChartAreas[0].CursorX.AutoScroll = true;
chart1.ChartAreas[0].CursorY.AutoScroll = true;
chart1.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
chart1.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
DateTime intervall = timelist.Min().AddHours(3);
chart1.ChartAreas[0].AxisX.ScaleView.Zoom(chart1.ChartAreas[0].AxisX.Minimum, intervall.ToOADate());
// disable zoom-reset button
chart1.ChartAreas[0].AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// set scrollbar small change to blockSize
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = intervall.ToOADate();
}
}
제 문제는 스크롤 막대를 부드럽게 움직일 수 없다는 것입니다. Y 값만 플롯하고 AxisX.Maximum
, AxisX.Minimum
, AxisX.ScaleView.Zoom
에 대해 단지 double
값을 사용하고 AxisX.ScaleView.SmallScrollSize
에 대해서는 매력처럼 작동합니다. 그러나 X 값으로 DateTime
을 사용하자마자 나는 단계별로만 스크롤 할 수 있습니다. 누군가 이것을 능가하는 방법을 알고 있습니까? 나는이 코드 조각 장애물이라는 느낌이 :
// set scrollbar small change to blockSize (e.g. 100)
chart1.ChartAreas[0].AxisX.ScaleView.SmallScrollSize = intervall.ToOADate();
편집 :
X 축에 대한 간격이 자동으로이 범위가 chart1.ChartAreas[0].AxisX.ScaleView.Zoom
의 개의 zoomLevel에 의해 설정된다. 여기 사진이다
EDIT 2 :
X 축 값분마다 1의 값의 샘플링 시뮬레이션 날짜 시간 - 값이다 :
timelist.Add(DateTime.Now.AddMinutes(i + 2));
그것 때문에 간격을 설정하지 않은 많은 값입니다. 코드는이 방법으로 게시되므로 코드를 그대로 복사하여 바로 실행할 수 있습니다.
감사하지만, 불행히도 같은 결과. 나는 scrollbutton을 드래그 할 수없고 단계적으로 그래프를 부드럽게 움직일 수 없다. –
실제로 유창하게 스크롤하고 싶습니다. x 축 값에서 날짜와 시간을 어지럽히 지 않으면 작동합니다. 확대/축소 창은'chart1.ChartAreas [0] .AxisX.ScaleView.Zoom'에 의해 설정되며이 간격 내에서 미끄러 져야합니다. –
차트의 값에 대해 더 자세히 알려줘야합니다! 리프트를 끌면 크기가 적어도 픽셀 당 1 * 이동할 수 있습니다. 이 단계가 확실합니까? 데이터 포인트 일 수도 있고 점프 축 라벨 일 수도 있습니다. 더 많이 알지 못해서 말하기가 정말 어렵습니다. 이미지를 보지 않고. Axis.Interval을 설정 했습니까? – TaW