以下代码是在html页面中能看见表格并能根据表格中的数据生成柱状图  但我想不让两个同时 输出   加个按钮在按下按钮后在生成图像 可是了很多办法都不能实现望各位大虾  帮忙 谢谢

解决方案 »

  1.   

    先弄个image对象,隐藏,然后电击按钮,改变其src,显示图片.
      

  2.   

    在安全性许可的设置下,可以启用excel<HTML>
    <BODY>
    Press the button to start Excel and display quarterly data.
    <SCRIPT LANGUAGE="VBScript">
    Function CreateNamesArray()
    ' Create an array to set multiple values at once.
      Dim saNames(5, 2)
      saNames(0, 0) = "John"  saNames(0, 1) = "Smith"
      saNames(1, 0) = "Tom"
      saNames(1, 1) = "Brown"
      saNames(2, 0) = "Sue"
      saNames(2, 1) = "Thomas"
      saNames(3, 0) = "Jane"
      saNames(3, 1) = "Jones"
      saNames(4, 0) = "Adam"
      saNames(4, 1) = "Johnson"
      CreateNamesArray = saNames
    End Function
    </SCRIPT><SCRIPT LANGUAGE="JScript"> 
    function AutomateExcel()
    {   // Start Excel and get Application object.
          var oXL = new ActiveXObject("Excel.Application");
           
          oXL.Visible = true;
          
       // Get a new workbook.
          var oWB = oXL.Workbooks.Add();
          var oSheet = oWB.ActiveSheet;
             
       // Add table headers going cell by cell.
          oSheet.Cells(1, 1).Value = "First Name";
          oSheet.Cells(1, 2).Value = "Last Name";
          oSheet.Cells(1, 3).Value = "Full Name";
          oSheet.Cells(1, 4).Value = "Salary";
             
       // Format A1:D1 as bold, vertical alignment = center.
          oSheet.Range("A1", "D1").Font.Bold = true;
          oSheet.Range("A1", "D1").VerticalAlignment =  -4108; //xlVAlignCenter
             
       // Create an array to set multiple values at once.   // Fill A2:B6 with an array of values (from VBScript).
          oSheet.Range("A2", "B6").Value = CreateNamesArray();
         
       // Fill C2:C6 with a relative formula (=A2 & " " & B2).
          var oRng = oSheet.Range("C2", "C6");
          oRng.Formula = "=A2 & \" \" & B2";
             
       // Fill D2:D6 with a formula(=RAND()*100000) and apply format.
          oRng = oSheet.Range("D2", "D6");
          oRng.Formula = "=RAND()*100000";
          oRng.NumberFormat = "$0.00";
             
       // AutoFit columns A:D.
          oRng = oSheet.Range("A1", "D1");
          oRng.EntireColumn.AutoFit();
             
       // Manipulate a variable number of columns for Quarterly Sales Data.
          DispalyQuarterlySales(oSheet);
            
       // Make sure Excel is visible and give the user control
       // of Excel's lifetime.
          oXL.Visible = true;
          oXL.UserControl = true;
    }
          
    function DispalyQuarterlySales(oWS)
    {
          var iNumQtrs, sMsg, iRet;    // Number of quarters to display data for.
          iNumQtrs = 4;
                   
        // Starting at E1, fill headers for the number of columns selected.
          var oResizeRange = oWS.Range("E1", "E1").Resize(1,iNumQtrs);
          oResizeRange.Formula = "=\"Q\" & COLUMN()-4 & CHAR(10) & \"Sales\"";
             
        // Change the Orientation and WrapText properties for the headers.
          oResizeRange.Orientation = 38;
          oResizeRange.WrapText = true;
             
        // Fill the interior color of the headers.
          oResizeRange.Interior.ColorIndex = 36;
             
        // Fill the columns with a formula and apply a number format.
          oResizeRange = oWS.Range("E2", "E6").Resize(5,iNumQtrs);
          oResizeRange.Formula = "=RAND()*100";
          oResizeRange.NumberFormat = "$0.00";
             
        // Apply borders to the Sales data and headers.
          oResizeRange = oWS.Range("E1", "E6").Resize(6,iNumQtrs);
          oResizeRange.Borders.Weight = 2;  // xlThin
             
        // Add a Totals formula for the sales data and apply a border.
          oResizeRange = oWS.Range("E8", "E8").Resize(1,iNumQtrs);
          oResizeRange.Formula = "=SUM(E2:E6)";
        // 9 = xlEdgeBottom      
          oResizeRange.Borders(9).LineStyle = -4119; //xlDouble
          oResizeRange.Borders(9).Weight = 4; //xlThick
             
        // Add a Chart for the selected data.      oResizeRange = oWS.Range("E2:E6").Resize(5,iNumQtrs);
          var oChart = oWS.Parent.Charts.Add();
          oChart.ChartWizard(oResizeRange, -4100, null, 2);  // -4100 = xl3dColumn
          oChart.SeriesCollection(1).XValues = oWS.Range("A2", "A6");
          for (iRet = 1; iRet <= iNumQtrs; iRet++) {
             oChart.SeriesCollection(iRet).Name = "=\"Q" + iRet + "\"";
          }
          oChart.Location(2, oWS.Name); // 2 = xlLocationAsObject
             
        // Move the chart so as not to cover your data.
          oWS.Shapes("Chart 1").Top = oWS.Rows(10).Top;
          oWS.Shapes("Chart 1").Left = oWS.Columns(2).Left;
    }
    </SCRIPT>
    <P><INPUT id=button1 type=button value="Start Excel" 
              onclick="AutomateExcel"></P>
    </BODY>
    </HTML>
    如果非要在页面中,只能自己div等实现了
      

  3.   

    你也可以按照下面的思路<HTML>
    <BODY>
    <SCRIPT LANGUAGE="JavaScript"> 
    function DrawGraph()
    {a = new Array(100,200,300,150)
    b = document.createElement("span")
    b.innerHTML="&nbsp;"div1 = document.createElement("DIV")
    div1.style.width="20px"
    div1.style.height=a[0]+"px"
    div1.style.display="inline"
    div1.style.backgroundColor="red"
    document.getElementById("graph").appendChild(div1)
    b = document.createElement("span")
    b.innerHTML="&nbsp;"
    document.getElementById("graph").appendChild(b)div1 = document.createElement("DIV")
    div1.style.width="20px"
    div1.style.height=a[1]+"px"
    div1.style.display="inline"
    div1.style.backgroundColor="red"
    document.getElementById("graph").appendChild(div1)
    b = document.createElement("span")
    b.innerHTML="&nbsp;"
    document.getElementById("graph").appendChild(b)div1 = document.createElement("DIV")
    div1.style.width="20px"
    div1.style.height=a[2]+"px"
    div1.style.display="inline"
    div1.style.backgroundColor="red"
    document.getElementById("graph").appendChild(div1)
    b = document.createElement("span")
    b.innerHTML="&nbsp;"
    document.getElementById("graph").appendChild(b)div1 = document.createElement("DIV")
    div1.style.width="20px"
    div1.style.height=a[3]+"px"
    div1.style.display="inline"
    div1.style.backgroundColor="red"
    document.getElementById("graph").appendChild(div1)
    }
    </SCRIPT>
    <P><INPUT  type=button value="画图" 
              onclick="DrawGraph()"></P>
    <div id="graph"></div>
    </BODY>
    </HTML>
      

  4.   


    <HTML>
    <BODY><div style="width:200px;filter:alpha(opacity=30);opacity: 0.5;-moz-opacity:0.5;">半透明</div>
    <SCRIPT LANGUAGE="JavaScript"> 
    function DrawGraph()
    {a = new Array(100,200,300,150)
    for(int i=0;i<a.length;i++)
    {
    b = document.createElement("span")
    b.innerHTML="&nbsp;" div1 = document.createElement("DIV")
    div1.style.width="20px"
    div1.style.height=a[i]+"px"
    div1.style.display="inline"
    div1.style.backgroundColor="red"
    document.getElementById("graph").appendChild(div1)
    b = document.createElement("span")
    b.innerHTML="&nbsp;"
    document.getElementById("graph").appendChild(b)}
    }
    </SCRIPT>
    <P><INPUT  type=button value="画图" 
              onclick="DrawGraph()"></P>
    <div id="graph"></div>
    </BODY>
    </HTML>怎么报脚本错误 阿
      

  5.   

    希望隊你有幫助
    -----------------
    <script language="VBScript">   
    Sub Window_OnLoad()    Dim erweishuzu(3,11)
    Dim dblValuesX(12)
          Dim GraphXname(11)
           Dim chConstants
           Dim chartseries(3)
           Dim axValueAxisY
           Dim axValueAxisX
    Dim m
    m=1
    For i=0 To 3
    For j=0 To 11
    erweishuzu(i,j)=m
    m=m+2
    Next
    Next
           erweishuzu(2,2)=0
           erweishuzu(2,3)=0
           erweishuzu(2,11)=0
          
        For i=0 to 11  
    GraphXname(i) ="0"&i+1&"月"
    If i+1>9 Then
    GraphXname(i)=i+1&"月"
    End If
    Next
    Set chConstants = objChart.Constants                                                      
    With objChart                                                                             
    .Clear                                                                              
         .Charts.Add                                                                         
         .Charts(0).Type = chConstants.chChartTypeLineMarkers
         For i=0 To 3                                
         .Charts(0).SeriesCollection.Add                                                     
            Next
    .Charts(0).hastitle=true
            .Charts(0).title.caption="2007年"
            .Charts(0).title.font.size="14"
            .Charts(0).title.font.color="#808080"
            .Charts(0).title.font.bold=true  
        For i=0 To 3                                                   
          Set chartseries(i) = .Charts(0).SeriesCollection(i)
          Next     chartseries(0).SetData chConstants.chDimCategories, chConstants.chDataLiteral, GraphXname
         
          For i=0 To 3
         
    For j=0 To 11
    dblValuesX(j)=erweishuzu(i,j)
    Next      chartseries(i).SetData chConstants.chDimValues, chConstants.chDataLiteral, dblValuesX Next       For i=0 To 3                                
          chartseries(i).Caption = "A"&i                                              
    Next
         
          For i=0 To 3                                              
          Set chartseries(i) = Nothing                                                          
    Next
                                                                     
         .Charts(0).HasLegend = True                                                         
         .Charts(0).Legend.Position = chConstants.chLegendPositionBottom                     
         .Charts(0).Axes(chConstants.chAxisPositionLeft).MajorTickMarks = chConstants.chTickMarkInside  
         .Charts(0).Axes(chConstants.chAxisPositionBottom).MajorTickMarks = chConstants.chTickMarkInside
                                                                
         Set axValueAxisY = .Charts(0).Axes(chConstants.chAxisPositionLeft)
    '     Set axValueAxisY = .Charts(0).Axes(chConstants.chAxisPositionRight)                 
    axValueAxisY.Font.Size = 9                         
    axValueAxisY.Scaling.Maximum = 100       
    axValueAxisY.Scaling.Minimum = 0                
    axValueAxisY.MajorUnit = 5              
    axValueAxisY.NumberFormat = "###,0"            
    Set axValueAxisY = Nothing                            
    Set axValueAxisX = .Charts(0).Axes(chConstants.chAxisPositionBottom)
    axValueAxisX.Font.Size = 9                              
    Set axValueAxisX = Nothing                              
    End With                                                    
    End Sub                                                     
    </script>    
    <table border="0" cellspacing="0" cellpadding="3" width="100%">
    <tr>
    <td width="74%">
    <object id="objChart"
    classid="CLSID:0002E500-0000-0000-C000-000000000046"
    style="width:80%;height:290">                                
    </object>                                                           
    </td>
    </table>
    <br>
    </body>
      

  6.   

    若你的应用环境局限于IE的话,你到是可以使用 VML 来生成 chat 表