我的意思是:在html文件中通过:
<object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:100%;height:350"></object>
加入一个ChartSpace组件,可以通过VBScript对这个组件进行操作,显示一个柱状图,代码如下:<html>
  <head>
    <title></title>
  </head>
  <body>
    <object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:100%;height:350"></object><script language=vbs>
Sub Window_OnLoad()
Dim categories(3), values(3)    ' Create a column chart with three series and four categories, showing the 
    ' percentage of voters for the 1992 presidential election by race/ethic group.    ' Create an array of strings representing the categories.
    ' The categories will be the same for all three series.
    categories(0) = "White"
    categories(1) = "Black"
    categories(2) = "Asian"
    categories(3) = "Latino"    ' Clear the contents of the chart workspace. This removes
    ' any old charts that may already exist and leaves the chart workspace
    ' completely empty. One chart object is then added.
    ChartSpace1.Clear
    ChartSpace1.Charts.Add
    Set c = ChartSpace1.Constants    ' Add three series to the chart.
    ChartSpace1.Charts(0).SeriesCollection.Add
    ChartSpace1.Charts(0).SeriesCollection.Add
    ChartSpace1.Charts(0).SeriesCollection.Add
    
    ' Series one contains election data for Perot.
    ' Set the series caption (the text that appears in the legend).
    ChartSpace1.Charts(0).SeriesCollection(0).Caption = "Perot"    ' Set the categories for the first series (this collection is zero-based) 
    ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimCategories, c.chDataLiteral, categoriesvalues(0) = 0.2 ' The White value.
values(1) = 0.06 ' The Black value.
values(2) = 0.17 ' The Asian value.
values(3) = 0.13 ' The Latino value.ChartSpace1.Charts(0).SeriesCollection(0).Caption = "Perot"
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimCategories, c.chDataLiteral, categories
ChartSpace1.Charts(0).SeriesCollection(0).SetData c.chDimValues, c.chDataLiteral, values    ' Series two contains election data for Clinton.
    ' Update the values array, then set the chart data.
    values(0) = 0.38 ' The White value.
    values(1) = 0.82 ' The Black value.
    values(2) = 0.28 ' The Asian value.
    values(3) = 0.62 ' The Latino value.    ChartSpace1.Charts(0).SeriesCollection(1).Caption = "Clinton"
    ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimCategories, c.chDataLiteral, categories
    ChartSpace1.Charts(0).SeriesCollection(1).SetData c.chDimValues, c.chDataLiteral, values    ' Series two contains election data for Bush.
    ' Update the values array, and then set the chart data.
    values(0) = 0.42 ' The White value.
    values(1) = 0.12 ' The Black value.
    values(2) = 0.55 ' The Asian value.
    values(3) = 0.25 ' The Latino value.    ChartSpace1.Charts(0).SeriesCollection(2).Caption = "Bush"
    ChartSpace1.Charts(0).SeriesCollection(2).SetData c.chDimCategories, c.chDataLiteral, categories
    ChartSpace1.Charts(0).SeriesCollection(2).SetData c.chDimValues, c.chDataLiteral, values    ' Make the chart legend visible, format the left value axis as percentage, 
    ' and specify that value gridlines are at 10% intervals.
    ChartSpace1.Charts(0).HasLegend = True
    ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).NumberFormat = "0%"
    ChartSpace1.Charts(0).Axes(c.chAxisPositionLeft).MajorUnit = 0.1
End Sub
</script>
  </body>
</html>我把上面的vbs代码改成js代码,没有显示成功。我想请问,javascript能否实现相同的功能?在js中是否可以调用ChartSpace的属性和方法?如何调用?能否提供一个使用js操作ChartSpace生成柱状图、饼图的例子?或者提供参考资料也可以,谢谢了!

解决方案 »

  1.   

    我把上面文件中的vbs修改成js如下:<html>
    <head>
    <title></title>
    </head>
    <body onload="window_onload()">
    <object id=ChartSpace1 classid=CLSID:0002E500-0000-0000-C000-000000000046 style="width:100%;height:350"></object><script language="javascript" type="text/javascript">
    function window_onload(){
    var categories = new Array(4);
    var values = new Array(4);
    var chartsp = document.all.ChartSpace1;    // Create a column chart with three series and four categories, showing the 
        // percentage of voters for the 1992 presidential election by race/ethic group.    // Create an array of strings representing the categories.
        // The categories will be the same for all three series.
        categories[0] = "White";
        categories[1] = "Black";
        categories[2] = "Asian";
        categories[3] = "Latino";    // Clear the contents of the chart workspace. This removes
        // any old charts that may already exist and leaves the chart workspace
        // completely empty. One chart object is then added.
        chartsp.Clear();
        chartsp.Charts.Add();
        var c = chartsp.Constants;    // Add three series to the chart.
        chartsp.Charts[0].SeriesCollection.Add();    //********************************
    //****************此处报错:Charts.0.SeriesCollection 为空或不是对象**********
        chartsp.Charts[0].SeriesCollection.Add();
        chartsp.Charts[0].SeriesCollection.Add();
        
        // Series one contains election data for Perot.
        // Set the series caption [the text that appears in the legend].
        chartsp.Charts[0].SeriesCollection[0].Caption = "Perot";    // Set the categories for the first series [this collection is zero-based] 
        chartsp.Charts[0].SeriesCollection[0].SetData(c.chDimCategories,c.chDataLiteral,categories); values[0] = 0.2; // The White value.
    values[1] = 0.06; // The Black value.
    values[2] = 0.17; // The Asian value.
    values[3] = 0.13; // The Latino value.

    chartsp.Charts[0].SeriesCollection[0].Caption = "Perot";
    chartsp.Charts[0].SeriesCollection[0].SetData(c.chDimCategories,c.chDataLiteral,categories);
    chartsp.Charts[0].SeriesCollection[0].SetData(c.chDimValues,c.chDataLiteral,values);    // Series two contains election data for Clinton.
        // Update the values array, then set the chart data.
        values[0] = 0.38 // The White value.
        values[1] = 0.82 // The Black value.
        values[2] = 0.28 // The Asian value.
        values[3] = 0.62 // The Latino value.    chartsp.Charts[0].SeriesCollection[1].Caption = "Clinton";
        chartsp.Charts[0].SeriesCollection[1].SetData(c.chDimCategories,c.chDataLiteral,categories);
        chartsp.Charts[0].SeriesCollection[1].SetData(c.chDimValues,c.chDataLiteral,values);    // Series two contains election data for Bush.
        // Update the values array, and then set the chart data.
        values[0] = 0.42; // The White value.
        values[1] = 0.12; // The Black value.
        values[2] = 0.55; // The Asian value.
        values[3] = 0.25; // The Latino value.    chartsp.Charts[0].SeriesCollection[2].Caption = "Bush";
        chartsp.Charts[0].SeriesCollection[2].SetData(c.chDimCategories,c.chDataLiteral,categories);
        chartsp.Charts[0].SeriesCollection[2].SetData(c.chDimValues,c.chDataLiteral,values);    // Make the chart legend visible, format the left value axis as percentage, 
        // and specify that value gridlines are at 10% intervals.
        chartsp.Charts[0].HasLegend = true;
        chartsp.Charts[0].Axes[c.chAxisPositionLeft].NumberFormat = "0%";
        chartsp.Charts[0].Axes[c.chAxisPositionLeft].MajorUnit = 0.1;
    }
    </script>
      </body>
    </html>在IE里报错说:Charts.0.SeriesCollection 为空或不是对象,不知何故?
      

  2.   

    var categories = "White\tBlack\tAsian\tLatino";
    var values = "0.2\t0.06\t0.17\t0.13";