可以图片保存到文件上的阿>>可以自由控制它的位置?
什么意思?

解决方案 »

  1.   

    保存为文件;
    objBitmap.Save(Server.MapPath("x.jpg"),ImageFormat.Jpeg); 
    你说的控制它的位置是具体是指什么?
    node为一个Bitmap,你可以指定它的位置
    objGraphics.DrawImage(node,200,200,100,30);
      

  2.   

    我的意思是说能不能把生成的图表像对待一般的图片一个,任意把它放到table里!!
    它是一个动态生成的图,第次运行都不一样的。
      

  3.   

    <asp:Image ImageUrl="showImg.aspx" runat="server" />
      

  4.   

    秋水无恨的做法虽然不会出错,但还是没实现上面的功能。其它的控件都不见了.
    能否这样
    objBitmap.Save(Server.MapPath("x.jpg"),ImageFormat.Jpeg);
    <asp:Image ImageUrl="x.jpg" runat="server" />
    -- 
    而且可能会有多个图表.
      

  5.   

    你是不是用
    objBitmap.Save(Response.OutputStream,ImageFormat.Gif);
    将图片输出了?
    输出是一张图片,所以你不会看到其他的控件成生一个Bitmap之后,你不能用
    objGraphics.DrawImage画出那个图片吗?
      

  6.   

    这是我收藏的一段代码,希望对你有所帮助
    Imports System.Drawing
    Imports System.Drawing.Imaging
    Imports System.Data
    Imports System.Data.SqlClient
    Public Class Charts
        Inherits System.Web.UI.Page
        Dim Values As ArrayList = New ArrayList()
        Dim Captions As ArrayList = New ArrayList()
        Dim Connection As SqlConnection
        Dim DR As SqlDataReader
        Dim Command As SqlCommand
        Dim TableName As String
        Dim SumNum As Int32
        Dim Item_Count As Integer
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            TableName = Request.QueryString("table")
            Connection = New SqlConnection(Application("SqlConString"))
            '统计数据到两个数组
            ReadData()
            '生成饼图
            DisplayPieChart()
        End Sub
        'This function returns a color for the bar and pie charts.
        Private Function GetColor(ByVal itemIndex As Integer) As Color
            Dim objColor As Color
            Select Case itemIndex
                Case 0
                    objColor = Color.Blue
                Case 1
                    objColor = Color.Red
                Case 2
                    objColor = Color.Yellow
                Case 3
                    objColor = Color.Purple
                Case 4
                    objColor = Color.Orange
                Case 5
                    objColor = Color.Brown
                Case 6
                    objColor = Color.Gray
                Case 7
                    objColor = Color.Maroon
                Case Else
                    objColor = Color.Green
            End Select
            Return objColor
        End Function
        Sub ReadData()
            Dim SqlString As String
            Dim I As Integer
            Dim Num_Temp As Int16
            SumNum = 0
            I = 0
            SqlString = "Select r1,count(r1) as cc from " + TableName + " group by r1"
            Command = New SqlCommand(SqlString, Connection)
            Command.Connection.Open()
            DR = Command.ExecuteReader
            While DR.Read
                Captions.Add(Convert.ToString(DR.GetString(0)))
                Values.Add(Convert.ToInt16(DR("cc")))
                Item_Count += 1
                SumNum = SumNum + Convert.ToInt16(DR("cc"))
            End While
            DR.Close()
            Command.Connection.Close()
        End Sub
        Sub DisplayPieChart()
            '定义显示的字体
            Dim FontLeg As Font
            Dim FontTitle As Font
            FontLeg = New Font("宋体", 10)
            FontTitle = New Font("宋体", 15)
            '确定图片的大小,及其各个元素的大小,宽度都一样
            Dim ImageWidth As Integer
            Dim ImageHeight As Integer
            Dim ChartHeight As Integer
            Dim LegendHeight As Integer
            Dim TitleHeight As Integer
            Dim BufferSpace As Integer = 15
            ImageWidth = 300
            LegendHeight = FontLeg.Height * (Item_Count + 1) + BufferSpace
            TitleHeight = FontTitle.Height + BufferSpace
            ChartHeight = ImageWidth
            ImageHeight = ImageWidth + LegendHeight + TitleHeight + BufferSpace
            '画出底图
            Dim WjhBitmap As Bitmap
            Dim WjhGraphic As Graphics
            Dim WjhBrush As Brush
            WjhBitmap = New Bitmap(ImageWidth, ImageHeight)
            WjhGraphic = Graphics.FromImage(WjhBitmap)
            WjhBrush = New SolidBrush(Color.Black)
            WjhGraphic.FillRectangle(New SolidBrush(Color.White), 0, 0, ImageWidth, ImageHeight)
            ' 画出饼图
            Dim PieRec As Rectangle
            PieRec = New Rectangle(0, TitleHeight, ImageWidth, ChartHeight)
            Dim CurrentDegree As Single = 0.0F
            Dim I As Integer
            For I = 0 To Item_Count - 1
                WjhGraphic.FillPie(New SolidBrush(GetColor(I)), PieRec, CurrentDegree, Convert.ToSingle(Values(I) / SumNum * 360))
                CurrentDegree = CurrentDegree + Convert.ToSingle(Values(I) / SumNum * 360)
            Next
            '画出标题
            Dim TitleRecF As RectangleF
            TitleRecF = New RectangleF(0, 0, ImageWidth, TitleHeight)
            Dim WjhFormat As StringFormat = New StringFormat()
            WjhFormat.Alignment = StringAlignment.Center
            WjhFormat.LineAlignment = StringAlignment.Center
            WjhGraphic.DrawString("统计结果", FontTitle, WjhBrush, TitleRecF, WjhFormat)
            '画出图例
            WjhGraphic.DrawRectangle(New Pen(Color.Black, 2), 0, ImageHeight - LegendHeight, ImageWidth, LegendHeight)
            For I = 0 To Item_Count - 1
                WjhGraphic.FillRectangle(New SolidBrush(GetColor(I)), 5, ImageHeight - LegendHeight + FontLeg.Height * I + 5, 10, 10)
                WjhGraphic.DrawString(Captions(I) + " ---- " + Convert.ToString(Values(I)), FontLeg, WjhBrush, 20, ImageHeight - LegendHeight + FontLeg.Height * I + 1)
            Next
            '画总计
            WjhGraphic.DrawString("总计: " + Str(SumNum), FontLeg, WjhBrush, 5, ImageHeight - FontLeg.Height - 5)
            WjhBitmap.Save(Response.OutputStream, ImageFormat.Jpeg)
        End Sub
    End Class
      

  7.   

    ameng_2002(星星之火) 也是用Response.OutputStream把图表输出,和我做法是一样的,现在我是说怎么样在web页面上自由的放置它,我要把它输出到具体的位置,比如一个表格中的单元格.
      

  8.   

    问题解决了,谢谢 qiushuiwuhen(秋水无恨)。
      

  9.   

    你是什么c# 写的吗public void IM_OnClick(Object sender,ImageClickEventArgs e)
    {
      int PageX=e.X;
      int PageY=e.Y;
      xf.Text=PageX.ToString();
      yf.Text=PageY.ToString();
    }