Code example for use MS Chart with PivotCubeX

Useful things for PivotCubeX - code examples, algorithm solutions etc

Moderator: Alex Zencovich

Code example for use MS Chart with PivotCubeX

Postby AlexZencovich » Thu Apr 12, 2007 3:45 pm

Private Function GetMaxSeries(MaxZSeries As Integer, Count As Integer) As Integer
If MaxZSeries <> 0 Then
If Count <= MaxZSeries Then
Result = Count
Else
Result = MaxZSeries
End If
Else
Result = Count
End If
GetMaxSeries = Result
End Function

Private Sub FillMSChart()
If Not PCX.MapActive Then
Exit Sub
End If

Dim i, j As Integer
Dim MaxZSeries As Integer

Dim X() As Variant

Measure = 0 'Summa
MaxZSeries = 0

With PCX.MapIntf
If (.ColumnsCount = 0) And (.RowsCount = 0) Then
Exit Sub
End If

If .RowDimCount = 0 Then
Exit Sub
End If

If .ColumnDimCount = 0 Then
Exit Sub
End If
k = GetMaxSeries(MaxZSeries, .TopColumns.ChildCount)
ReDim X(0 To k, 0 To .TopRows.ChildCount)

For i = 0 To .TopColumns.ChildCount - 1
If i > k Then
Exit For
End If
'sr1.Marks.Visible = ShowMarks
'sr1.Title := FTopColumn.Childs[i].Caption;
X(i + 1, 0) = .TopColumns.Childs(i).Caption
For j = 0 To .TopRows.ChildCount - 1
If .TopRows.Childs(j).IsNode And .TopRows.Childs(j).NodeExpanded Then
GoTo NextJI
End If
If Not .TopRows.Childs(j).Visible Then
GoTo NextJI
End If
X(i + 1, j + 1) = .Cells(.TopColumns.Childs(i).Position, .TopRows.Childs(j).Position, Measure)
X(0, j + 1) = .TopRows.Childs(j).Caption
NextJI:
Next j, i

End With

With MSChart1
.ToDefaults

.ChartData = X


.chartType = VtChChartType2dBar

' Establish the number of items in the group
numSeries = .Plot.SeriesCollection.Count

' Now add a black line to the border of each of the shapes
For iCount = 1 To numSeries
' .GraphObj.Plot.SeriesCollection(iCount).DataPoints(-1).Brush.FillColor.Set fillColours(iScheme, iCount, 1), fillColours(iScheme, iCount, 2), fillColours(iScheme, iCount, 3)
.Plot.SeriesCollection(iCount).DataPoints(-1).EdgePen.VtColor.Set 0, 0, 0
Next iCount

' Turn off the background grids
.Plot.Axis(VtChAxisIdX).AxisGrid.MajorPen.Style = VtPenStyleNull
.Plot.Axis(VtChAxisIdY).AxisGrid.MajorPen.Style = VtPenStyleNull
.Plot.Axis(VtChAxisIdY2).AxisGrid.MajorPen.Style = VtPenStyleNull
.Plot.Wall.Pen.Style = VtPenStyleNull


' Setup the colours of the pens

' For iCount = 1 To numSeries
' .Plot.SeriesCollection(iCount).Pen.VtColor.Set penColours(iScheme, iCount, 1), penColours(iScheme, iCount, 2), penColours(iScheme, iCount, 3)
' Next iCount

' Define the background colour to white


.Backdrop.Fill.Brush.FillColor.Set 255, 255, 255
.Backdrop.Fill.Style = VtFillStyleBrush

End With

MSChart1.Plot.AutoLayout = True

With MSChart1.Legend

' Add the legend in the required position

.Location.Visible = True
.VtFont.Name = "Arial"
.VtFont.Size = 8


.Location.LocationType = VtChLocationTypeTop
.VtFont.Effect = VtFontStyleBold

End With
Best regards,

Alex Zencovich
-------------------------------------------------------------------------------------------------------------------------------------------
www.pivotcube.com - OLAP solution for Delphi, C++ Builder and ActiveX environment
AlexZencovich
Site Admin
 
Posts: 580
Joined: Sun Jun 18, 2006 10:09 am

Error with code

Postby ccascante » Thu Apr 19, 2007 2:11 pm

Alex,

I tried to run the example code and I get an error when accesing: PCX.MapIntf.ColumnsCount and all the properties in PCX.MapIntf.

"Object does not support this action"

I add a watch to PCX.MapIntf and every one of the elements of the collection has "Object does not support this action" as value, also the properties "ColumnsCount" and "RowsCount" don't even exist, there are: ColumnCellsCount, ColumnDimCount, RowCellsCount and RowDimCount.

Please help me,

CCASCANTE
ccascante
User
 
Posts: 18
Joined: Fri Jul 07, 2006 8:46 pm

Postby AlexZencovich » Thu Apr 19, 2007 3:24 pm

1. PCX.MapIntf is not nil only when control active.
2. Sorry, there was old example. ou should get
RowCellsCount/ColumnCellsCount instead.

Please note - if you have used VFP, you may need to import typle library in VFP (I have no idea how to do that, but I know VFP has some problem with ActiveX properties access, althrough it allows access to methods)
Best regards,

Alex Zencovich
-------------------------------------------------------------------------------------------------------------------------------------------
www.pivotcube.com - OLAP solution for Delphi, C++ Builder and ActiveX environment
AlexZencovich
Site Admin
 
Posts: 580
Joined: Sun Jun 18, 2006 10:09 am


Return to PivotCubeX

Who is online

Users browsing this forum: No registered users and 0 guests

cron