User (Legacy) Posted January 6, 2003 Report Share Posted January 6, 2003 I'm trying to create box and whisker plots. Method I'm using is : 1. Create a series of variable (by series) width bars (using Volume) 2. Bars are stacked The code below works, with all except the Mean Value (this should plot as a thin horizontal line, similar to high and low whiskers), but it plots as a thin bar. Can someone tell me what I'm doing wrong. I'd prefer to use non-clustered bars (ie they can be overlaid on each other, rather than stacked, so if anyone has any suggestions in this direction...) Cheers Paul CODE >>>>>>>> Option Explicit Public Type CaBoxplotInfo bUsed As Boolean sTitle As String dMedian As Double dMean As Double dHighHinge As Double dLowHinge As Double dHighWhisker As Double dLowWhisker As Double dOutliers() As Double dExtremeOutliers() As Double iNumOutliers As Integer iNumExtremeOutliers As Integer iNumRecords As Integer End Type Sub test(ChartFX1 As ChartFX) 'ChartFX1 is the ocx on the form Dim newBox(1 To 20) As CaBoxplotInfo Dim intCount As Integer Dim intCount1 As Integer 'dummy data for testing For intCount = 1 To 20 newBox(intCount).dMedian = 3.7 newBox(intCount).dHighHinge = 4# * intCount * 0.5 newBox(intCount).dLowHinge = 3# * intCount * 0.5 newBox(intCount).dMean = newBox(intCount).dLowHinge + (newBox(intCount).dHighHinge - newBox(intCount).dLowHinge) / 2 newBox(intCount).dHighWhisker = 4.5 * intCount * 0.5 newBox(intCount).dLowWhisker = 2.5 * intCount * 0.5 newBox(intCount).iNumOutliers = 2 newBox(intCount).iNumExtremeOutliers = 2 Next 'graphics Dim i ChartFX1.Gallery = BAR ChartFX1.CylSides = 20 ChartFX1.Axis(AXIS_Y).Min = 0 ChartFX1.Axis(AXIS_Y).Max = 60 ChartFX1.OpenDataEx COD_INIVALUES, 6, UBound(newBox) For i = 0 To UBound(newBox) - 1 ChartFX1.Series(0).YFrom(i) = newBox(i + 1).dLowWhisker ChartFX1.Series(1).YFrom(i) = newBox(i + 1).dLowWhisker ChartFX1.Series(2).YFrom(i) = newBox(i + 1).dLowHinge ChartFX1.Series(3).YFrom(i) = newBox(i + 1).dMean 'this does not work correctly ChartFX1.Series(4).YFrom(i) = newBox(i + 1).dHighHinge ChartFX1.Series(5).YFrom(i) = newBox(i + 1).dHighWhisker Next ChartFX1.CloseData COD_INIVALUES ChartFX1.OpenDataEx COD_VALUES, 6, UBound(newBox) For i = 0 To UBound(newBox) - 1 ChartFX1.ValueEx(0, i) = newBox(i + 1).dLowWhisker ChartFX1.ValueEx(1, i) = newBox(i + 1).dLowHinge - newBox(i + 1).dLowWhisker ChartFX1.ValueEx(2, i) = newBox(i + 1).dHighHinge - newBox(i + 1).dLowHinge ChartFX1.ValueEx(3, i) = 0 ChartFX1.ValueEx(4, i) = newBox(i + 1).dHighWhisker - newBox(i + 1).dHighHinge ChartFX1.ValueEx(5, i) = 0 Next i ChartFX1.CloseData COD_VALUES ChartFX1.Series(1).Stacked = True ChartFX1.Series(2).Stacked = True ChartFX1.Series(3).Stacked = True ChartFX1.Series(4).Stacked = True ChartFX1.Series(5).Stacked = True ChartFX1.Series(0).Volume = 10 * intCount * 0.2 ChartFX1.Series(1).Volume = 2 * intCount * 0.2 ChartFX1.Series(2).Volume = 10 * intCount * 0.2 ChartFX1.Series(3).Volume = 2 * intCount * 0.2 ChartFX1.Series(4).Volume = 2 * intCount * 0.2 ChartFX1.Series(5).Volume = 10 * intCount * 0.2 End Sub Link to comment Share on other sites More sharing options...
Software FX Posted January 6, 2003 Report Share Posted January 6, 2003 You need to get rid of the stacked option and set Cluster = True, this way you will have complete control over where each bar starts and ends. By setting Stacked = True, Chart FX will accumulate the values which is causing the median to be a "thin bar". By setting YFrom and ValueEx to the same value to achieve a horizontal line. -- FP Software FX, Inc. Link to comment Share on other sites More sharing options...
User (Legacy) Posted January 7, 2003 Author Report Share Posted January 7, 2003 Thanks for that, it worked fine I have another problem when using multiple colour. I want set a different color fill for the High/Low Hinge bar when there is positive skew (using Median/Mean relationship, but the code below changes all colours. Can you see what I'm doing wrong? tia Paul >>>>>>>>>>>>>> other code here >>>>>>>>>>>>>> .MultipleColors = True .OpenDataEx COD_COLORS, 6 + intMaxOutliers + intMaxExtremeOutliers, 0 'set colors for all but the high/low hinge (we set this individually later) .Series(0).Color = RGB(0, 0, 0) .Series(1).Color = RGB(0, 0, 0) .Series(2).Color = RGB(0, 0, 0) .Series(4).Color = RGB(0, 0, 0) .Series(5).Color = RGB(0, 0, 0) 'outliers For intCount = 6 To 6 + intMaxOutliers - 1 .Series(intCount).Color = RGB(0, 0, 255) Next 'extreme outliers For intCount = intCount To intCount + intMaxExtremeOutliers - 1 .Series(intCount).Color = RGB(255, 0, 0) Next If pblnShowSkew Then 'color the high/low bar individually depending on skew For intCount = 0 To UBound(pNewBox) - 1 If pNewBox(intCount + 1).dMedian < pNewBox(intCount + 1).dMean Then ' the index algorithm is taken from the CHARTFX Help doco .Color(3 + (intCount * .NSeries)) = RGB(255, 0, 0) Else .Color(3 + (intCount * .NSeries)) = RGB(255, 255, 255) End If Next Else 'color all bars the same For intCount = 0 To UBound(pNewBox) - 1 .Color(3 + (intCount * .NSeries)) = RGB(255, 255, 255) Next End If .CloseData COD_COLORS >>>>>>>>>>>>>> other code here >>>>>>>>>>>>>> "SoftwareFX Support" <support@softwarefx.com> wrote in message news:<sXBbhVctCHA.2684@webserver1.softwarefx.com>... > You need to get rid of the stacked option and set Cluster = True, this way > you will have complete control over where each bar starts and ends. By > setting Stacked = True, Chart FX will accumulate the values which is causing > the median to be a "thin bar". > > By setting YFrom and ValueEx to the same value to achieve a horizontal line. > > -- > FP > Software FX, Inc. > "SoftwareFX Support" <support@softwarefx.com> wrote in message news:sXBbhVctCHA.2684@webserver1.softwarefx.com... > You need to get rid of the stacked option and set Cluster = True, this way > you will have complete control over where each bar starts and ends. By > setting Stacked = True, Chart FX will accumulate the values which is causing > the median to be a "thin bar". > > By setting YFrom and ValueEx to the same value to achieve a horizontal line. > > -- > FP > Software FX, Inc. > > Link to comment Share on other sites More sharing options...
Software FX Posted January 8, 2003 Report Share Posted January 8, 2003 The code changes all colors to black as you are assigning Black to all series from 0 to 5. Is that what you mean ? What exactly do you want to get ? Any color property can receive either an RGB value or a Palette index. For example: .Series(0).Color = CHART_PALETTECOLOR or 0 .Series(1).Color = CHART_PALETTECOLOR or 1 ... -- FP Software FX, Inc. Link to comment Share on other sites More sharing options...
User (Legacy) Posted January 8, 2003 Author Report Share Posted January 8, 2003 I want individual boxes to be filled with red or white depending on the skew. I've been using the following code to achieve this (which doesn't work) : If pNewBox(intCount + 1).dMedian < pNewBox(intCount + 1).dMean Then ' the index algorithm is taken from the CHARTFX Help doco .Color(3 + (intCount * .NSeries)) = RGB(255, 0, 0) Else .Color(3 + (intCount * .NSeries)) = RGB(255, 255, 255) End If "SoftwareFX Support" <support@softwarefx.com> wrote in message news:ShdSJEytCHA.1056@webserver1.softwarefx.com... > The code changes all colors to black as you are assigning Black to all > series from 0 to 5. Is that what you mean ? What exactly do you want to get > ? > > Any color property can receive either an RGB value or a Palette index. For > example: > > .Series(0).Color = CHART_PALETTECOLOR or 0 > .Series(1).Color = CHART_PALETTECOLOR or 1 > ... > > -- > FP > Software FX, Inc. > > Link to comment Share on other sites More sharing options...
Software FX Posted January 9, 2003 Report Share Posted January 9, 2003 1) Are you turning on CT_EACHBAR, you need to do this if you want each pint to be colored independently. 2) You either color each point independently or you color per series, you can't do both. You need to: a) Take out the code: .Series(i).Color = ... Allocate the appropriate number of colors: .OpenDataEx COD_COLORS, (6 + intMaxOutliers + intMaxExtremeOutliers) * NUMBEROFPOINTS, 0 -- FP Software FX, Inc. Link to comment Share on other sites More sharing options...
User (Legacy) Posted January 10, 2003 Author Report Share Posted January 10, 2003 That all works now. The box and whiskers look good. Thanks for you help Paul "SoftwareFX Support" <support@softwarefx.com> wrote in message news:1tcmIP$tCHA.2684@webserver1.softwarefx.com... > 1) Are you turning on CT_EACHBAR, you need to do this if you want each pint > to be colored independently. > > 2) You either color each point independently or you color per series, you > can't do both. You need to: > > a) Take out the code: > > .Series(i).Color = ... > > Allocate the appropriate number of colors: > > .OpenDataEx COD_COLORS, (6 + intMaxOutliers + intMaxExtremeOutliers) * > NUMBEROFPOINTS, 0 > > -- > FP > Software FX, Inc. > > Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.