我对编程很陌生,希望你能帮助我。我的任务是创建一个ChartGraph,我正在读取一个txt文件,它将x轴作为样本。我想要的是在我的X-aixs上有时间,在每个样本之间我有3毫秒
我的代码:
private void Se_livefeed_Load(object sender, EventArgs e)
{
List<double> dataList = opsamling.getList();
int blockSize = 1000;
// clear the chart
chart1.Series.Clear();
// fill the chart
var series = chart1.Series.Add("EKG");
series.ChartType = SeriesChartType.Line;
series.XValueType = ChartValueType.Int32;
for (int i = 0; i < dataList.Count; i++)
series.Points.AddXY(i, dataList[i]);
var chartArea = chart1.ChartAreas[series.ChartArea];
// set view range to [0,max]
chartArea.AxisX.Minimum = 0;
chartArea.AxisX.Maximum = dataList.Count;
// enable autoscroll
chartArea.CursorX.AutoScroll = true;
// let's zoom to [0,blockSize] (e.g. [0,100])
chartArea.AxisX.ScaleView.Zoomable = true;
chartArea.AxisX.ScaleView.SizeType = DateTimeIntervalType.Number;
int position = 0;
int size = blockSize;
chartArea.AxisX.ScaleView.Zoom(position, size);
// disable zoom-reset button (only scrollbar's arrows are available)
chartArea.AxisX.ScrollBar.ButtonStyle = ScrollBarButtonStyles.SmallScroll;
// set scrollbar small change to blockSize (e.g. 100)
chartArea.AxisX.ScaleView.SmallScrollSize = blockSize;
}
答案 0 :(得分:0)
您必须将索引转换为要用于x轴的单位。例如,如果要以毫秒显示它,并且因为每个样本(索引)之间有3毫秒:
series.XValueType = ChartValueType.Int32;
for (int i = 0; i < dataList.Count; i++)
series.Points.AddXY(3 * i, dataList[i]);
var chartArea = chart1.ChartAreas[series.ChartArea];
// set view range to [0,max]
chartArea.AxisX.Minimum = 0;
chartArea.AxisX.Maximum = dataList.Count * 3;
如果您想在几秒钟内显示它:
series.XValueType = ChartValueType.Double;
for (int i = 0; i < dataList.Count; i++)
series.Points.AddXY(0.003 * i, dataList[i]);
var chartArea = chart1.ChartAreas[series.ChartArea];
// set view range to [0,max]
chartArea.AxisX.Minimum = 0;
chartArea.AxisX.Maximum = dataList.Count * 0.003;