Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

A problem about display in a form with a ScatterGraph

Solved!
Go to solution

Hi All!
 
Now I want to make a picture that can be zoomed out and in with the display window in a form with a ScatterGraph window. I have previously attempted to make this picture as background, but the backgroundpicture cannot be zoomed out with the display window. How can I fix it?

Here is the picture:

CIE 1931

 

 

Or I must calculate a large amout of points to sign on the xy coordination without the picture, and how can I sign out quickly, because it takes a long time to calculate.

0 Kudos
Message 1 of 4
(4,837 Views)
Solution
Accepted by topic author sun at home

Hi there,

 

You can zoom/pan an image along with the plot in graphs. Here is some code snippet showing how you can do it.

 

 








        Image img =
Bitmap.FromFile("myImage.jpg");



        // in pixels, this is the place
where the image will be drawn


       
RectangleF initialRectangle = Rectangle.Empty;



        // in data coordinates, to map the
image


       
Range xRange;

        Range yRange;



        private void PlotMyData()

        {


           
// plot your data here


           
double[] xData = new double[] { 3, 5, 7, 5, 8, 3, 7, 8, 2, 6 };

            double[]
yData = new double[] { 9, 1, 2, 6, 8, 3, 3, 6, 2, 2 };

           
scatterGraph1.PlotXY(xData, yData);


 


           
//xRange and yRange define the plot area bounds left-top to bottom-right


           
xRange = new Range(xAxis1.Range.Minimum, xAxis1.Range.Maximum);

            yRange =
new Range(yAxis1.Range.Minimum, yAxis1.Range.Maximum);

           
RecalculateImageBounds();

        }




        //Simply map the data coordinates
to pixel values


       
// left-top and bottom-right positions should be mapped.


       
private void RecalculateImageBounds()

        {

            PointF
size = scatterPlot1.MapDataPoint(scatterGraph1.PlotAreaBounds,
xRange.Maximum, yRange.Minimum);


           
initialRectangle.Location =
scatterPlot1.MapDataPoint(scatterGraph1.PlotAreaBounds, xRange.Minimum,
yRange.Maximum);

           
initialRectangle.Width = size.X - initialRectangle.Location.X;

           
initialRectangle.Height = size.Y - initialRectangle.Location.Y;

        }


 


     
  // Simply draw the image.


       
private void scatterGraph1_BeforeDrawPlot(object sender, BeforeDrawXYPlotEventArgs
e)

        {

           
RecalculateImageBounds();

           
e.Graphics.DrawImage(img, initialRectangle.X, initialRectangle.Y,
initialRectangle.Width, initialRectangle.Height);

        }








 

Make sure the image is of good quality so that you can zoom in fairly close.

 

Hope this helps. 

Message Edited by vcp on 03-08-2010 12:25 AM
0 Kudos
Message 2 of 4
(4,804 Views)

Hi, I have used your code and it works fine but there is a little bug.

 

You will don´t see the Majordivions if you enabled this setting. The divisions are below the picture like following one shows.You will see the divisions if you zoom near the x-axis. I would say, that the graph plots the divisions before the BeforePlotEvent and so you overwrite the divisions with your picture!

 

 

Unbenannt.jpg

 

 

But if you change the event form BeforedrawPlot to BeforeDrawPlotArea so you will draw the picture before the the system plots the divisions. And you will get the following result.

 

 

Unbenannt2.jpg

 

0 Kudos
Message 3 of 4
(4,580 Views)

Hi I found a bug in this code, it creates the wrong color if ill zoome some steps.  The Problem occures after this step:

 

 

initialRectangle.Width = size.X - initialRectangle.Location.X;

initialRectangle.Height = size.Y - initialRectangle.Location.Y;

 

initialRectangle->X becomes more and more smaller and ends at -32768 You see it if you write

 

 

if(initialRectangle->X == -32768) 
{
Debug.WriteLine("X:"+initialRectangle.Location.X); Debug.WriteLine("Y:"+initialRectangle.Location.Y); Debug::WriteLine("SIZEX:"+size->X); Debug.WriteLine("SIZEY:"+size->Y); }

e.Graphics.DrawImage...

 

The result looks like the following picture:

 

 

Unbenannt.jpg

 

Maybe anyone has a solution for this problems, because i dont know how to work around this -32...

 

 

 

0 Kudos
Message 4 of 4
(3,933 Views)