打印本文 打印本文 关闭窗口 关闭窗口
ASP.NET动态创建图象
作者:武汉SEO闵涛  文章来源:敏韬网  点击数3253  更新时间:2009/4/23 10:48:39  文章录入:mintao  责任编辑:mintao
p;    if (symbol = "msft") then
            Dim StockValues() as Single = { 60, 110, 120, 180, 185, 190, 240, 290 }
            myChartLine.Width = 5
            myChartLine.Color = Color.Blue
            myChartLine.LineStyle = DashStyle.Solid
            myChartLine.Title = "Microsoft Corp. (MSFT)"
            myChartLine.Symbol = "MSFT"
            myChartLine.Values = StockValues
            return myChartLine
        elseif (symbol = "sun") then
            Dim StockValues() as Single = { 180, 155, 125, 60, 25, 15, 10, 3 }
            myChartLine.Width = 5
            myChartLine.Color = Color.Red
            myChartLine.LineStyle = DashStyle.Dot
            myChartLine.Title = "Sun Corp. (Sun)"
            myChartLine.Symbol = "Sun"
            myChartLine.Values = StockValues
            return myChartLine
        end if
        return nothing
    End Function
    Sub Page_Load(Sender as Object, E as EventArgs) 
        '''' Generate Chart Data For Image....
        Dim XAxes() as String = { "9:00AM", "9:30AM", "10:00AM", "11:00AM", "12:00AM", "1:00PM", "1:30PM" }
        Dim MyChartData as New ChartData
        MyChartData.YTickSize = 20
        MyChartData.YMax = 250
        MyChartData.YMin = 0
        MyChartData.XAxisTitles = XAxes
        Dim Symbols() as String = Request.QueryString.GetValues("symbols")
        if (Not Symbols = Nothing) then
           for i=0 to Symbols.Length-1
              Dim stockValue as ChartLine = GetStockDetails(symbols(i).ToLower)
              If (stockValue <> nothing) then
                 myChartData.Lines.Add(stockValue)
              End if
           Next 
        end if
        '''' Create In-Memory BitMap of JPEG
        Dim MyChartEngine as New ChartEngine
        Dim StockBitMap as BitMap = MyChartEngine.DrawChart(600, 400, myChartData)
        '''' Render BitMap Stream Back To Client
        StockBitMap.Save(Response.OutputStream, ImageFormat.JPEG)
     End Sub
</script>

ChartEngine.cs:
using System.WinForms;
using System.Collections;
using System.Collections.Bases;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.ComponentModel;
using System;
using System.IO;
namespace ChartGenerator  {
    //Core Line Data structure 
    public struct LineData {
        public float[] LineValues  ;
        public string LineTitle ;
        public string LineSymbol ;
    }

    //Line Data plus display style information 
    public class ChartLine {
        private Color lineColor ;
        private LineData lineData ;
        private DashStyle lineStyle ;
        private int lineWidth  ;
        //Constructors
        public ChartLine() :base() {}
        public ChartLine(LineData lineData) :base() {
            this.lineData = lineData;
        }
        //Properties
        public Color Color { 
            get { return lineColor ; }
            set { lineColor = value ; }
        }
        public DashStyle LineStyle {
            get { return lineStyle ; }
            set { lineStyle = value ; }
        }
        
        public string Symbol {
            get { return lineData.LineSymbol ; }
            set { lineData.LineSymbol = value ; }
        }
        public string Title {
            get { return lineData.LineTitle ; }
            set { lineData.LineTitle = value ; }
        }
        public float[] Values {
            get { return lineData.LineValues ; }
            set { lineData.LineValues = value ; }
        }
        public int Width { 
            get { return lineWidth ; }
            set { lineWidth = value ; }
        }

        //Methods
        public void SetLineData(LineData lineData) {
            this.lineData = lineData;
        }
    }

    //Chart Data structure
    public class ChartData {
     &

上一页  [1] [2] [3] [4] [5]  下一页

打印本文 打印本文 关闭窗口 关闭窗口