簡潔にするために、マイクロソフトが提供する「WinFormsChartSamples」を確認しました。私が知りたかったのは、Chartcontrols のズームとスクロールを有効にする方法です。そこに示されている例はかなり短いです。
using System.Windows.Forms.DataVisualization.Charting;
...
// Set automatic zooming
chart1.ChartAreas["Default"].AxisX.ScaleView.Zoomable = true;
chart1.ChartAreas["Default"].AxisY.ScaleView.Zoomable = true;
// Set automatic scrolling
chart1.ChartAreas["Default"].CursorX.AutoScroll = true;
chart1.ChartAreas["Default"].CursorY.AutoScroll = true;
...
私はこれを試しましたが、ズームもスクロールも何も起こりませんでした。私は2つのことを試しました:
Form1.Designer.cs で、その情報をグラフに追加しました。
chartArea1.Name = "ChartArea1"; chartArea1.CursorX.AutoScroll = true; chartArea1.CursorY.AutoScroll = true; chartArea1.AxisX.ScaleView.Zoomable = true; chartArea1.AxisY.ScaleView.Zoomable = true; this.chart1.ChartAreas.Add(chartArea1); this.chart1.Cursor = System.Windows.Forms.Cursors.Cross; legend1.Name = "Legend1"; this.chart1.Legends.Add(legend1); this.chart1.Location = new System.Drawing.Point(297, 62); this.chart1.Name = "chart1"; series1.ChartArea = "ChartArea1"; series1.Legend = "Legend1"; series1.Name = "Series1"; this.chart1.Series.Add(series1); this.chart1.Size = new System.Drawing.Size(963, 668); this.chart1.TabIndex = 6; this.chart1.Text = "chart1";
Form1.cs のコンストラクターに直接追加しようとしました。
おそらく、シリーズにデータを追加するために OpenFileDialog を使用していることに言及することが重要です。
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
Stream fileStream = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open File..";
//First the description of the file separated by "|"
fDialog.Filter = "((ASC files)| *.asc";
fDialog.InitialDirectory = @"C:\";
//Show Messagebox if the file was loaded (Source: MSDN - FileDialog.FilterProperty)
if (fDialog.ShowDialog() == DialogResult.OK)
{
MessageBox.Show("The File was loaded successfully.");
try
{
if ((fileStream = fDialog.OpenFile()) != null)
{
using (fileStream)
{
//Insert code for reading the stream here.
Spectrum newSpectrum = new Spectrum(chart1.Series.Count, fDialog.FileName,
fDialog.SafeFileName, DataHandler.readSpectrumFromFile(fileStream));
addSpectrumToView(newSpectrum);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
どんなアドバイスでも大歓迎です、事前に感謝します、
BC++