Why does auto Zoom/Scroll not work for my Chart?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi folks,
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px; text-align:left to make it short I checked on the <strong style="margin:0px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left "WinFormsChartSamples" <span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px; text-align:left provided
by Microsoft. What I wanted to know is how to enable zooming and scrolling for Chartcontrols. The example which is shown there is pretty short.
<pre class="prettyprint 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;

...[/code]
<br/>

<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
I tried this and nothing happened, no zooming and no scrolling. I tried two things:
<ol style="margin:0px 0px 1em 30px; padding:0px; border:0px; font-size:14px; vertical-align:baseline; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
<li style="margin:0px; padding:0px; border:0px; vertical-align:baseline; background-color:transparent; word-wrap:break-word
<p style="padding-right:0px; vertical-align:baseline; background-color:transparent; clear:both; word-wrap:break-word
In Form1.Designer.cs I added that information to the chart.
</ol>
<pre class="prettyprint 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";[/code]
<br/>

2. <span style="background-color:transparent; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px; text-align:left I tried to add it directly into the constructor in Form1.cs.
<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left
Perhaps it is important to mention that I am using OpenFileDialog in order to add data to the series:
<pre class="prettyprint private void openToolStripMenuItem_Click(object sender, EventArgs e)
{

Stream fileStream = null;
OpenFileDialog fDialog = new OpenFileDialog();
fDialog.Title = "Open File..";

fDialog.Filter = "((ASC files)| *.asc";
fDialog.InitialDirectory = @"C:";


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);
}

}
}[/code]
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px; text-align:left Any advice is welcome, thanks in advance,
<span style="font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; font-size:14px; line-height:18px; text-align:left GenAesth<br/>

<br/>

<p style="padding-right:0px; font-size:14px; vertical-align:baseline; clear:both; word-wrap:break-word; font-family:Arial,Liberation Sans,DejaVu Sans,sans-serif; line-height:18px; text-align:left


<p style="text-align:left <span style=" <span style="font-size:14px; line-height:18px <br/>


View the full article
 
Back
Top