C# Charting API를 처음 사용하려고하는데 문제가 있습니다. 나는 두 개의 하드웨어 신호를 가지고있다. 그래프에 플롯하고자하는 x 축은 -10에서 10으로, y 축은 -10에서 10까지 사용한다. SeriesChartType.Point 차트 타입을 사용하고있다. 하나의 경우를 제외하고는 코드가 예상대로 작동합니다. AddXY 함수를 사용하여 차트에 점을 추가합니다. 실제로 값은 하드웨어에서 나오지만이 예제에서는 단순히 값을 하드 코딩했습니다.C# Chart API를 사용하여 첫 번째 점을 (0,0)으로 표시 할 때 X 축 값이 자동으로 증가합니다.
내가 겪고있는 문제는 첫 번째 점에 x 축 값이 0이면 차트가 0을 무시하고 x 축 값을 각 후속 점마다 하나씩 증가시키는 것입니다. 플롯되어있다.
문제점을 설명하기 위해 다음과 같은 간단한 예제를 만들었습니다. 내 x 축 값을 0으로, y 축 값을 2로 하드 코딩했습니다. 점을 그릴 때 첫 번째 점은 (1,2), 다음은 (2,2), 다음 (3,2)에 그려집니다. , (4,2) 그리고 마지막으로 (5,2).
첫 번째 점에 x 축 값이 0 인 경우에만 이것이 발생합니다. 다른 값이 있으면 차트가 영원히 올바르게 작동합니다. 나는 이것을 일으킬 수있는 것에 관해서는 손해보고있다.
다음 예제 코드를 참조하십시오
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
ConfigureChartSettings();
AddFakeData();
}
private void AddFakeData()
{
this.chart1.Series["Series1"].Points.AddXY(0, 2); //Gets plotted at (1,2)
this.chart1.Series["Series1"].Points.AddXY(0, 2); //Gets plotted at (2,2)
this.chart1.Series["Series1"].Points.AddXY(0, 2); //Gets plotted at (3,2)
this.chart1.Series["Series1"].Points.AddXY(0, 2); //Gets plotted at (4,2)
this.chart1.Series["Series1"].Points.AddXY(0, 2); //Gets plotted at (5,2)
}
private void ConfigureChartSettings()
{
//Set point chart type
this.chart1.Series["Series1"].ChartType = SeriesChartType.Point;
//Set the market size
this.chart1.Series["Series1"].MarkerSize = 5;
//Set the marker shape to a circle
this.chart1.Series["Series1"].MarkerStyle = MarkerStyle.Circle;
//X and Y values are both between -10 and 10 so set the x and y axes accordingly
this.chart1.ChartAreas["ChartArea1"].AxisX.Minimum = -10.0;
this.chart1.ChartAreas["ChartArea1"].AxisX.Maximum = 10.0;
this.chart1.ChartAreas["ChartArea1"].AxisY.Minimum = -10.0;
this.chart1.ChartAreas["ChartArea1"].AxisY.Maximum = 10.0;
//Set the titles of the X and Y axes
this.chart1.ChartAreas["ChartArea1"].AxisX.Title = "XSignalName";
this.chart1.ChartAreas["ChartArea1"].AxisY.Title = "YSignalName";
//Set the Intervals of the X and Y axes,
this.chart1.ChartAreas["ChartArea1"].AxisX.Interval = 5;
this.chart1.ChartAreas["ChartArea1"].AxisY.Interval = 5;
//Set the MajorGrid interval to 5.
this.chart1.ChartAreas["ChartArea1"].AxisX.MajorGrid.Interval = 5;
this.chart1.ChartAreas["ChartArea1"].AxisY.MajorGrid.Interval = 5;
//Set the MinorGrid interval to 1.
this.chart1.ChartAreas["ChartArea1"].AxisX.MinorGrid.Interval = 1;
this.chart1.ChartAreas["ChartArea1"].AxisY.MinorGrid.Interval = 1;
//Set the MinorGrid style to Dot so that it is less obstructive.
this.chart1.ChartAreas["ChartArea1"].AxisX.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
this.chart1.ChartAreas["ChartArea1"].AxisY.MinorGrid.LineDashStyle = ChartDashStyle.Dot;
//Enable the minor grids.
this.chart1.ChartAreas["ChartArea1"].AxisX.MinorGrid.Enabled = true;
this.chart1.ChartAreas["ChartArea1"].AxisY.MinorGrid.Enabled = true;
}
}
이미 이런 일 수 있고 나는 그것이 매우 간단 뭔가 확신 이유를 알아 내려고 시간의 무리를 낭비했습니다를하지만 그럴 수 없어 대답을 찾은 것 같습니다. 어떤 도움이라도 대단히 감사하겠습니다.
감사합니다. Dominique에게 감사의 말을 전합니다. 덧글에 덧글을 남길 수는 없으므로 여기에 추가하겠습니다. 방금 시도한이 문제를 해결하는 것 같습니다. 감사! 나는 어제 같은 것을하려고 노력하는 것에 대해 생각했다. 그러나 그것은 정말로 조금 해키게 보였다. 나는 MSChart에게 그렇게 "똑똑한"일을 그만 두라고 말할 수있는 또 다른 방법이 있기를 바라고 있었지만 이것이 효과가있는 것처럼 보입니다. – Jon
좋아, 나는 너무 일찍 말했다. 추가 테스트를 통해 실제로 문제가 해결되지는 않습니다. 이 작업을하는 방식으로 마지막 X 점만 그래프에 저장하려고합니다. 예를 들어 X = 5라고 말하면됩니다. Points.Count> = 5 일 때 새로운 점을 추가하기 전에 Points.RemoveAt (0)을 호출합니다. 그런 다음 x 축 값이 0 인 행에 5 개의 점을 플롯하면 문제가 다시 나타납니다. MsChart에게 "똑똑한"것을 시도하는 것을 멈추기 위하여 간단하게 말하는 재산이 있는지 누군가는 알고있다. x 축 값이 0이 아닌 그래프의 빈 지점을 항상 유지하려고 시도하는 것보다 훨씬 깔끔합니다. – Jon