Results 1 to 4 of 4

Thread: [RESOLVED] Excel Graph

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Resolved [RESOLVED] Excel Graph

    Hi
    Can anyone show me how to rotate an xy scatter graph in Excel2003 from vb.net? The rotate property is only valid for 3d graph, i think.

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Excel Graph

    If there is no rotate property in excel, you will have to do it manually, and the output you get will be a bitmap. Is this acceptable?
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Re: Excel Graph

    Ok, I see what you mean. I guess a bitmap would work.

  4. #4
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: [RESOLVED] Excel Graph

    Here's some code I had to tweak but found here http://www.vb-helper.com/howto_net_image_rotate.html
    Code:
            Const PI As Single = 3.14159
            Dim bm_in As New Bitmap(PictureBox1.Image)
    
            ' Make an array of points defining the
            ' image's corners.
            Dim wid As Integer = bm_in.Width
            Dim hgt As Integer = bm_in.Height
            Dim corners As Point() = { _
                New Point(0, 0), _
                New Point(wid, 0), _
                New Point(0, hgt), _
                New Point(wid, hgt)}
    
            ' Translate to center the bounding box at the origin.
            Dim cx As Integer = CType(wid / 2, Integer)
            Dim cy As Integer = CType(hgt / 2, Integer)
            Dim i As Integer
            For i = 0 To 3
                corners(i).X -= cx
                corners(i).Y -= cy
            Next i
    
            ' Rotate.
            Dim theta As Double = Single.Parse("90") * PI _
                / 180.0
            Dim sin_theta As Single = CType(Math.Sin(theta), Single)
            Dim cos_theta As Single = CType(Math.Cos(theta), Single)
            Dim X As Single
            Dim Y As Single
            For i = 0 To 3
                X = corners(i).X
                Y = corners(i).Y
                corners(i).X = CType(X * cos_theta + Y * sin_theta, Integer)
                corners(i).Y = CType(-X * sin_theta + Y * cos_theta, Integer)
            Next i
    
            ' Translate so X >= 0 and Y >=0 for all corners.
            Dim xmin As Single = corners(0).X
            Dim ymin As Single = corners(0).Y
            For i = 1 To 3
                If xmin > corners(i).X Then xmin = corners(i).X
                If ymin > corners(i).Y Then ymin = corners(i).Y
            Next i
            For i = 0 To 3
                corners(i).X -= CType(xmin, Integer)
                corners(i).Y -= CType(ymin, Integer)
            Next i
    
            ' Create an output Bitmap and Graphics object.
            Dim bm_out As New Bitmap(CInt(-2 * xmin), CInt(-2 * _
                ymin))
            Dim gr_out As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bm_out)
    
            ' Drop the last corner lest we confuse DrawImage, 
            ' which expects an array of three corners.
            ReDim Preserve corners(2)
    
            ' Draw the result onto the output Bitmap.
            gr_out.DrawImage(bm_in, corners)
    
            ' Display the result.
            PictureBox2.Image = bm_out
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width