使用chart编写了一个asp组件.准备让chart输出一个图表bmp文件.然后asp程序来显示这个bmp.
在asp组件中我是动态创建了chart和series.在SaveToBitmapFile时总提示"Control '' has no parent window"下面我贴一下我的代码

解决方案 »

  1.   

    unit ShowChart;{$WARN SYMBOL_PLATFORM OFF}interfaceuses
      ComObj, ActiveX, AspTlb, WMChart_TLB, StdVcl, TeEngine, Series, ExtCtrls, TeeProcs, Chart, MXGRAPH;type
      TShowChart = class(TASPObject, IShowChart)
      protected
        procedure OnEndPage; safecall;
        procedure OnStartPage(const AScriptingContext: IUnknown); safecall;
        procedure AddChart(const ChartTitle, SeriesType: WideString; ChartWidth,
          ChartHeight: SYSINT); safecall;
        procedure ShowChart; safecall;  private
        MyChart: TChart;
        MySeries : TChartSeries ;
      end;implementationuses ComServ, Unit1;procedure TShowChart.OnEndPage;
    begin
      inherited OnEndPage;
    end;procedure TShowChart.OnStartPage(const AScriptingContext: IUnknown);
    begin
      inherited OnStartPage(AScriptingContext);
    end;procedure TShowChart.AddChart(const ChartTitle, SeriesType: WideString;
      ChartWidth, ChartHeight: SYSINT);
    begin
      //创建Chart
      MyChart:=Tchart.Create(NIL);
      MyChart.Parent:=NIL;
      MyChart.Width:=ChartWidth;
      MyChart.Height:=ChartHeight;
      //创建Series
      if SeriesType='Pie' then
        MySeries:=TPieSeries.Create(nil)
      else
        MySeries:=TBarSeries.Create(nil);
      MySeries.ParentChart:=MyChart;
      //设置Chart和Series
      MySeries.Marks.Visible:=true;             //图上显示标签
      Myseries.Marks.Style:=smsLabelValue;      //标签样式
      MyChart.Title.Text.Clear;
      MyChart.Title.Text.Add(ChartTitle);       //标题
      MyChart.Legend.Alignment:=laBottom;
      MyChart.Legend.TextStyle:=ltsRightValue;
      MyChart.Legend.ColorWidth:=18;
      MySeries.PercentFormat:='##0.# %';
      MyChart.SaveToBitmapFile('TestAspObjChart.bmp');   ///***********此处出错**************end;initialization
      TAutoObjectFactory.Create(ComServer, TShowChart, Class_ShowChart,
        ciMultiInstance, tmApartment);
    end.
      

  2.   

    procedure TShowChart.AddChart(const ChartTitle, SeriesType: WideString;
      ChartWidth, ChartHeight: SYSINT);
    begin
      //创建Chart
      MyChart:=Tchart.Create(NIL);
      MyChart.Parent:=NIL;
    这里能不能传递一个HANDLE到一个父类??估计就这里的问题吧
      

  3.   

    应该是这儿的问题.但我不知道该给他一个什么类.如果是from一个窗口的话绝对没有问题.程序绝对通过.但我不清楚asp组件可以写一个from?
      

  4.   

    正是因为我不知道该给他一个什么handle.所以我才加了一个nil.
    郁闷的我不行.
      

  5.   

    to:aiirii(ari-爱的眼睛)
     老大.我求你了.我都快哭了.
      

  6.   

    这样呢?
      if SeriesType='Pie' then
        MySeries:=TPieSeries.Create(MyChart)
      else
        MySeries:=TBarSeries.Create(MyChart);
      

  7.   

    不可以.都试过了.
    我想是否可以通过流的方式输出chart?
      

  8.   

    //  MyChart:=Tchart.Create(NIL);
    //  MyChart.Parent:=NIL;
    CHART必须有一个parent。Form_Temp := TForm.Create(NIL);
    MyChart.Parent:=Form_Temp;
      

  9.   

    感谢大家.
    问题自己解决.
    我下载了TeeChart7.0
    它支持gif流.
    function TShowChart.Get_ShowChart: OleVariant;
    var S:TmemoryStream;
      j:integer;
      p:pointer;
    begin
      s:=TmemoryStream.Create;
      //将chart转换成GIF格式
      With TGIFExportFormat.Create do
      try
        Panel:=MyChart;//这个MyChart就是我在其它地方画好的Chart
        SaveToStream(S);//保存到流里
      finally
        Free;
      end;  MyChart.Free;
      j:=S.Size;
      result:=varArrayCreate([0,j-1],varByte);//创建variant数组
      p:=VarArrayLock(result);
      S.Seek(0,soFromBeginning);
      S.Read(p^,j);//将GIF流返回,在ASP中用Response.binarywrite xxxx.ShowChart 就可以输出图形
      vararrayunlock(result);end;另外.在asp中.要指定Image/gif.才可以response.binarywrite xxxx.Showchart输出gif图片.否则输出的是文本.