none
vb6 中 chartspace 主次坐标轴问题 RRS feed

  • 问题


  • '引用 Microsoft office web components 11.0图表2个Y轴
    '左边对应的刻度是2个柱状图,右边刻度是3个线图
    '如果Ser11.Ungroup (True)   Ser12.Ungroup (True)   Ser13.Ungroup (True)
    '左右2边可以单独设置
    '但是Ser11,Ser12,Ser13对应的值与刻度不符
    '如果注释Ser11.Ungroup (True)   Ser12.Ungroup (True)   Ser13.Ungroup (True)图表不好看
    '因为柱状图和线图的数据相差太大,用了相同的刻度

    Option Explicit

    Private Sub Command1_Click()
       
        Dim strCategoryY As String
       
        Dim strValue1 As String
        Dim strValue2 As String
        Dim strValue3 As String
       
        Dim strValue11 As String
        Dim strValue12 As String
        Dim strValue13 As String

        Dim Chart1 As ChChart
        Set Chart1 = myChart.Charts.Add(0)

        Chart1.HasLegend = True
        Chart1.Legend.Position = ChartLegendPositionEnum.chLegendPositionBottom

        '给定标题
        Chart1.HasTitle = False

        '计算数据
        strCategoryY = "2008" + vbTab + "2009" + vbTab + "1月" + vbTab + "2月" + vbTab + "3月" + vbTab + "4月" + vbTab + "5月" + vbTab + "6月" + vbTab + "7月" + vbTab + "8月" + vbTab + "9月" + vbTab + "10月" + vbTab + "11月" + vbTab + "12月"
       
        strValue1 = "26.0" + vbTab + "31.0" + vbTab + "21.0" + vbTab + "8.0" + vbTab + " 56.0" + vbTab + "33.0" + vbTab + "29.0" + vbTab + "30.0" + vbTab + "12.0" + vbTab + "99.0" + vbTab + "40.0" + vbTab + "17.0" + vbTab + "26.0" + vbTab + "32.0"
        strValue2 = "25.0" + vbTab + "33.0" + vbTab + "23.0" + vbTab + "10.0" + vbTab + "54.0" + vbTab + "38.0" + vbTab + "23.0" + vbTab + "15.0" + vbTab + "22.0" + vbTab + "106.0   55.0" + vbTab + "16.0" + vbTab + "38.0" + vbTab + "20.0"
       
        strValue11 = "20" + vbTab + "26" + vbTab + "20" + vbTab + "12" + vbTab + "43" + vbTab + "25" + vbTab + "22" + vbTab + "32" + vbTab + "24" + vbTab + "80" + vbTab + "65" + vbTab + "20" + vbTab + "28" + vbTab + "26"
        strValue12 = "0" + vbTab + "0" + vbTab + "20.0" + vbTab + "32.0" + vbTab + "75.0" + vbTab + "100.0" + vbTab + "122.0" + vbTab + "154.0" + vbTab + "178.0" + vbTab + "258.0" + vbTab + "323.0" + vbTab + " 343.0" + vbTab + " 371.0" + vbTab + "397.0"
        strValue13 = "0" + vbTab + "0" + vbTab + "23.0" + vbTab + "33.0" + vbTab + "87.0" + vbTab + "125.0" + vbTab + "148.0" + vbTab + "163.0" + vbTab + "185.0" + vbTab + "291.0" + vbTab + "346.0" + vbTab + "362.0" + vbTab + "400.0" + vbTab + "420.0"
       
       
        Dim Ser1 As ChSeries, Ser2 As ChSeries, Ser11 As ChSeries, Ser12 As ChSeries, Ser13 As ChSeries
       
        Set Ser1 = Chart1.SeriesCollection.Add(0)
        Set Ser2 = Chart1.SeriesCollection.Add(0)
        Set Ser11 = Chart1.SeriesCollection.Add(1)
        Set Ser12 = Chart1.SeriesCollection.Add(1)
        Set Ser13 = Chart1.SeriesCollection.Add(1)
               
        Ser11.Type = ChartChartTypeEnum.chChartTypeLineMarkers
        Ser12.Type = ChartChartTypeEnum.chChartTypeLineMarkers
        Ser13.Type = ChartChartTypeEnum.chChartTypeLineMarkers
       
        '-----------主轴
        Call Ser1.SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, "A")
        '给定分类
        Call Ser1.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategoryY)
        '给定值
        Call Ser1.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue1)


        Call Ser2.SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, "B")
        '给定分类
        Call Ser2.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategoryY)
        '给定值
        Call Ser2.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue2)
       
       
        '-----------次轴
        Call Ser11.SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, "C")
        '给定分类
        Call Ser11.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategoryY)
        '给定值
        Call Ser11.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue11)
        Ser11.Ungroup (True)
       
        Call Ser12.SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, "D")
        '给定分类
        Call Ser12.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategoryY)
        '给定值
        Call Ser12.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue12)
        Ser12.Ungroup (True)

        Call Ser13.SetData(ChartDimensionsEnum.chDimSeriesNames, ChartSpecialDataSourcesEnum.chDataLiteral, "E")
        '给定分类
        Call Ser13.SetData(ChartDimensionsEnum.chDimCategories, ChartSpecialDataSourcesEnum.chDataLiteral, strCategoryY)
        '给定值
        Call Ser13.SetData(ChartDimensionsEnum.chDimValues, ChartSpecialDataSourcesEnum.chDataLiteral, strValue13)
        Ser13.Ungroup (True)


        '添加次轴坐标
        Dim AxesZ As ChAxis
        Set AxesZ = Chart1.Axes.Add(Ser13.Scalings(ChartDimensionsEnum.chDimValues))
        AxesZ.Position = chAxisPositionRight
        AxesZ.HasTitle = False
       
    End Sub

     

    2010年1月14日 15:58