使用 TChart activex 在 VBA Excel 中以 3D 形式绘制不透明表面的奇怪行为

如何解决使用 TChart activex 在 VBA Excel 中以 3D 形式绘制不透明表面的奇怪行为

我正在尝试使用 VBA EXCEL 中的 tee Chart 2021 在 3D 中绘制框。 壁箱有 3 个尺寸,高度、宽度和厚度。我正在做 仙女到现在为止。但我面临一个问题。我正在使用画布 on_afterdraw 方法 使墙壁表面不透明,但我的代码不能完全正常工作。

用同样的代码画两面平行的墙,其中之一画得很完美, 所有的表面(6 个面)都绘制为不透明的。另一个,六个中只有五个 脸被绘制为不透明的。我很困惑。

我附上了一些来自不同地点的图片 这样你就可以看到我的代码的奇怪行为。我也复制了 下面的代码。要运行它,您必须在 VBA Exel 中插入一个用户表单和一个实例 tChart 控件,并运行它。

为了简单起见,我已经注释掉了一些说明,所以只是墙壁平行于 绘制左下平面。

teeCommander 链接到图表,因此您可以移动、旋转、缩放它

是否有任何机构提供我可以遵循的提示解决我的问题。

Option Explicit

Private Const HORZSIZE = 4
Private Const VERTSIZE = 6

Private Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long,ByVal nIndex As Long) As Long


Dim newSeries As Integer
Dim planeType(1000) As String '  Vector to define plane type,XY,XZ,YZ,oblique
Dim notFinished As Boolean

Private Sub CheckBox1_Click()
   TChart1.Axis.Bottom.Visible = CheckBox1.Value

End Sub

Private Sub CheckBox2_Click()
   TChart1.Axis.Depth.Visible = CheckBox2.Value

End Sub

Private Sub CheckBox3_Click()
   TChart1.Axis.Left.Visible = CheckBox3.Value

End Sub

Private Sub prepareChart()
  Dim x,z As Integer

  TChart1.RemoveAllSeries
  TeeCommander1.Chart = TChart1
  
  TChart1.Aspect.zoom = 100
  TChart1.Aspect.Orthogonal = True
  TChart1.Aspect.Chart3DPercent = 100
  TChart1.Legend.Visible = False
  TChart1.Aspect.Rotation = 326
  TChart1.Aspect.HorizOffset = 0
  TChart1.Aspect.VertOffset = -170
  TChart1.Aspect.Elevation = 326


'  TChart1.Axis.Visible = False
  TChart1.Axis.Bottom.Visible = True ' CheckBox1.Value
  TChart1.Axis.Depth.Visible = True ' CheckBox2.Value
  TChart1.Axis.Left.Visible = True ' CheckBox3.Value
    
  TChart1.Axis.Bottom.Automatic = False
  TChart1.Axis.Bottom.Maximum = 100 ' TextBox1.Text
  TChart1.Axis.Bottom.Minimum = 0
  
  TChart1.Axis.Depth.Automatic = False
  TChart1.Axis.Depth.Maximum = 100 ' TextBox2.Text
  TChart1.Axis.Depth.Minimum = 0
  
  TChart1.Axis.Left.Automatic = False
  TChart1.Axis.Left.Maximum = 100 ' TextBox3.Text
  TChart1.Axis.Left.Minimum = 0
  
  TChart1.Walls.Visible = False

'  TChart1.AddSeries scPoint3D

   do_theChart
End Sub

Private Sub do_theChart()
    Dim Largo,Ancho,Alto,eCaja As Single
    
    Largo = 90 ' Cells(4,2)
    Ancho = 45 ' Cells(4,3)
    Alto = 30 ' Cells(4,4)
    eCaja = 5 ' Cells(4,5)
    
    TChart1.Aspect.OpenGL.Active = True
    
    notFinished = True
    drawBox3d TChart1,Largo,eCaja
    
    'makeIsoAxisBis TChart1
    

    notFinished = False

End Sub
Private Sub drawBox3d(theChart As TChart,eCaja)
  Dim newSeries As Integer
  Dim rads As Double
  Dim i,j As Integer
  Dim x0,y0,z0,x1,y1,z1

  Dim Angle

        drawSolidWall theChart,"XY",eCaja
        drawSolidWall theChart,Ancho - eCaja,eCaja

'        drawSolidWall theChart,"XZ",eCaja
'        drawSolidWall theChart,Alto - eCaja,"YZ",Largo - eCaja,eCaja
End Sub

Private Sub drawSolidWall(theChart As TChart,x0,plane,wLargo,wAlto,wEspesor)
      Select Case UCase(plane)
      Case "XY"
            makeXYPlane theChart,x0 + wLargo,y0 + wAlto,z0
            makeXYPlane theChart,z0 + wEspesor
            makeYZPlane theChart,z0 + wEspesor
            makeXZPlane theChart,z0 + wEspesor
      Case "XZ"
            makeXYPlane theChart,y0 + wEspesor,z0 + wAlto
            makeYZPlane theChart,z0 + wAlto
            makeXZPlane theChart,z0 + wAlto
      Case "YZ"
            makeXYPlane theChart,x0 + wEspesor,z0 + wLargo
            makeYZPlane theChart,z0 + wLargo
            makeXZPlane theChart,z0 + wLargo
      End Select

End Sub

Private Sub makeXYPlane(theChart As TChart,z1)
        addpoint3dSeriesBis theChart,newSeries
        With theChart
                .Series(newSeries).asPoint3D.AddXYZ x0,z1,"0",clTeeColor 'Punto 0
                .Series(newSeries).asPoint3D.AddXYZ x1,"1",clTeeColor ' Punto 1
                .Series(newSeries).asPoint3D.AddXYZ x1,"2",clTeeColor ' Punto 2
                .Series(newSeries).asPoint3D.AddXYZ x0,"3",clTeeColor  ' Punto 3
                .Series(newSeries).asPoint3D.AddXYZ x0,"4",clTeeColor  ' Punto 4
        End With
        planeType(newSeries) = "XY"

End Sub

Private Sub makeYZPlane(theChart As TChart,newSeries
        With theChart
                .Series(newSeries).asPoint3D.AddXYZ x1,clTeeColor ' Punto 2
                .Series(newSeries).asPoint3D.AddXYZ x1,clTeeColor ' Punto 3
                .Series(newSeries).asPoint3D.AddXYZ x1,clTeeColor ' Punto 4
        End With
        planeType(newSeries) = "YZ"
End Sub

Private Sub makeXZPlane(theChart As TChart,clTeeColor  ' Punto 4
        End With
        planeType(newSeries) = "XZ"
End Sub

Private Sub addpoint3dSeriesBis(theChart As TChart,lastSeriesPointer As Integer,Optional visiblePointer = False,Optional PenWidth = 2)
   With theChart
        .AddSeries (scPoint3D)
        lastSeriesPointer = .SeriesCount - 1
        .Series(lastSeriesPointer).asPoint3D.Pointer.Visible = False
        .Series(lastSeriesPointer).Pen.Width = 2
    End With
End Sub

Private Sub TChart1_OnAfterDraw()
    Dim i
    Dim ystart As Integer
    Dim ydelta1 As Integer
    Dim ydelta2 As Integer

    If notFinished Then
       Exit Sub
    End If
    ystart = 250: ydelta1 = 0: ydelta2 = 0
    With TChart1
            For i = 1 To TChart1.SeriesCount - 1
                  Select Case planeType(i)
                  Case "XY"
                                .Canvas.Brush.Color = RGB(225,225,225)
                                .Canvas.RectangleWithZ .Series(i).CalcXPos(0),.Series(i).CalcYPos(1),.Series(i).CalcXPos(2),.Series(i).CalcYPos(3),.Series(i).asPoint3D.CalcZPos(0)
                  Case "YZ"
                                .Canvas.Brush.Color = RGB(127,127,127)
                                .Canvas.Plane3D .Series(i).CalcXPos(0),.Series(i).CalcYPos(0),.Series(i).CalcYPos(2),.Series(i).asPoint3D.CalcZPos(0),.Series(i).asPoint3D.CalcZPos(2)
                  Case "XZ"
                                .Canvas.Brush.Color = RGB(200,200,200)
                                .Canvas.RectangleY .Series(i).CalcXPos(0),.Series(i).asPoint3D.CalcZPos(3)
                End Select
            Next i
    End With

End Sub

Private Sub UserForm_Click()

End Sub

Private Sub UserForm_Initialize()
    TeeCommander1.Chart = TChart1
    prepareChart
End Sub

The bottom cube has one of its faces missing or transparend

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?