|
histogramLayer Gaus |
Posted by Helmut on Jan-01-2018 00:58 |
|
Hi Peter,
Thanks for your help,
I am now at the Histogramm.cls and still have some questions.
How can I get the bar wider?
The distribution curve is OK.
slotSize must be 0.01 so that all values are displayed.
Call histogramLayer.setXData2 (minX + slotSize / 2 #, maxX - slotSize / 2 #)
Call histogramLayer.setXData2 (minX, maxX) ???
Thank you for your help and a happy new year!
Public Sub createChart(viewer As Object)
Dim cd As New ChartDirector.API
Dim i&
Dim Tage%, AltTage%
Dim db As DAO.Database
Dim P_Word As String
Dim Pfad As String
Dim MinDate As Date
Pfad = GetSetting("dato", "Pfade", "SpcPath")
P_Word = Chr(72) & Chr(97) & Chr(110) & Chr(105) & Chr(98) & Chr(97) & Chr(108) & Chr(108)
Set db = DBEngine.OpenDatabase("D:A_InstallHazecSpc1.mdb", False, False, ";pwd=" & P_Word)
Set Rec = db.OpenRecordset("Select * From Werte Where ID_Doku=1312 And Merk_Nr=1 And Version=2 and Right(Datum,4)=2012 Order by Datum, Zeit")
Rec.MoveLast
ReDim dataSeriesA(0 To Rec.RecordCount - 1)
'MsgBox UBound(dataSeriesA)
i = 0
Rec.MoveFirst
MinDate = CDate(Rec!datum & " " & Rec!Zeit)
Do While Not Rec.EOF
dataSeriesA(i) = Rec!wert
ID(i) = Rec!ID
i = i + 1
Rec.MoveNext
Loop
' This example demonstrates creating a histogram with a bell curve from raw data. About half of
' the code is to sort the raw data into slots and to generate the points on the bell curve. The
' remaining half of the code is the actual charting code.
'
' Generate a random guassian distributed data series as the input data for this example.
'Dim r As RanSeries
'Set r = cd.RanSeries(66)
'Dim dataSeriesA()
'dataSeriesA = r.getGaussianSeries(200, 100, 10)
'
' Classify the numbers into slots. In this example, the slot width is 5 units.
'
Dim slotSize As Single
slotSize = 0.01
' Compute the min and max values, and extend them to the slot boundary.
Dim m As ArrayMath
Set m = cd.ArrayMath(dataSeriesA)
'MsgBox m.Min
'MsgBox m.Max
Dim minX As Single
minX = m.Min / slotSize * slotSize
Dim maxX As Single
maxX = m.Max / slotSize * slotSize + slotSize
' We can now determine the number of slots
Dim slotCount As Single
slotCount = Int((maxX - minX + 0.5) / slotSize)
'slotCount = 20
ReDim frequency(slotCount - 1)
' Count the data points contained in each slot
For i = 0 To UBound(dataSeriesA)
Dim slotIndex As Single
slotIndex = (dataSeriesA(i) - minX) / slotSize
frequency(slotIndex) = frequency(slotIndex) + 1
Next
'
' Compute Normal Distribution Curve
'
' The mean and standard deviation of the data
Dim mean As Double
mean = m.Avg()
Dim stdDev As Double
stdDev = m.stdDev()
' The normal distribution curve (bell curve) is a standard statistics curve. We need to
' vertically scale it to make it proportion to the frequency count.
Dim scaleFactor As Double
scaleFactor = slotSize * (UBound(dataSeriesA) + 1) / stdDev / Sqr(6.2832)
' In this example, we plot the bell curve up to 3 standard deviations.
Dim stdDevWidth As Double
stdDevWidth = 3#
' We generate 4 points per standard deviation to be joined with a spline curve.
Dim bellCurveResolution As Long
bellCurveResolution = Int(stdDevWidth * 4 + 1)
ReDim bellCurve(bellCurveResolution - 1)
For i = 0 To UBound(bellCurve)
Dim z As Double
z = (2 * i - UBound(bellCurve)) * stdDevWidth / UBound(bellCurve)
bellCurve(i) = Exp(-z * z / 2) * scaleFactor
Next
' At this stage, we have obtained all data and can plot the chart.
'
' Create a XYChart object of size 600 x 360 pixels
Dim c As XYChart
Set c = cd.XYChart(600, 360)
' Set the plotarea at (50, 30) and of size 500 x 300 pixels, with transparent background and
' border and light grey (0xcccccc) horizontal grid lines
Call c.setPlotArea(50, 30, 500, 300, cd.Transparent, -1, cd.Transparent, &HCCCCCC)
' Display the mean and standard deviation on the chart
Call c.addTitle("Mean = " & c.formatValue(mean, "{value|3}") & ", Standard Deviation = " & _
c.formatValue(stdDev, "{value|3}"), "arial.ttf")
' Set the x and y axis label font to 12pt Arial
Call c.xAxis().setLabelStyle("arial.ttf", 12)
Call c.yAxis().setLabelStyle("arial.ttf", 12)
' Set the x and y axis stems to transparent, and the x-axis tick color to grey (0x888888)
Call c.xAxis().setColors(cd.Transparent, cd.textColor, cd.textColor, &H888888)
Call c.yAxis().setColors(cd.Transparent)
' Draw the bell curve as a spline layer in red (0xdd0000) with 2-pixel line width
Dim bellLayer As splineLayer
Set bellLayer = c.addSplineLayer(bellCurve, &HDD0000)
Call bellLayer.setXData2(mean - stdDevWidth * stdDev, mean + stdDevWidth * stdDev)
Call bellLayer.setLineWidth(2)
' No tooltip is needed for the spline layer
Call bellLayer.setHTMLImageMap("{disable}")
' Draw the histogram as bars in blue (0x6699bb) with dark blue (0x336688) border
Dim histogramLayer As barLayer
Set histogramLayer = c.addBarLayer(frequency, &H6699BB)
Call histogramLayer.setBorderColor(&H336688)
' The center of the bars span from minX + half_bar_width to maxX - half_bar_width
Call histogramLayer.setXData2(minX + slotSize / 2#, maxX - slotSize / 2#)
'Call histogramLayer.setXData2(minX, maxX)
'Call histogramLayer.setg
' Configure the bars to touch each other with no gap in between
Call histogramLayer.setBarGap(cd.TouchBar)
' Use rounded corners for decoration
Call histogramLayer.setRoundedCorners
' Tool tip for the histogram
Call histogramLayer.setHTMLImageMap("", "", "title='{value}'")
' Dim minValue As Double
' Dim maxValue As Double
' minValue = 2.2
' maxValue = 2.3
' Call c.xAxis().setLinearScale(minValue, maxValue, 0.01)
' Call c.layout
' minValue = c.xAxis().getMinValue()
' maxValue = c.xAxis().getMaxValue()
' ChartDirector by default will extend the x-axis scale by 0.5 unit to cater for the bar width.
' It is because a bar plotted at x actually occupies (x +/- half_bar_width), and the bar width
' is normally 1 for label based x-axis. However, this chart is using a linear x-axis instead of
' label based. So we disable the automatic extension and add a dummy layer to extend the x-axis
' scale to cover minX to maxX.
Call c.xAxis().setIndent(False)
Call c.addLineLayer2().setXData(minX, maxX)
' For the automatic y-axis labels, set the minimum spacing to 40 pixels.
Call c.yAxis().setTickDensity(40)
' Output the chart
Set viewer.Picture = c.makePicture()
' Include tool tip for the chart
viewer.ImageMap = c.getHTMLImageMap("clickable")
End Sub
|
Re: histogramLayer Gaus |
Posted by Peter Kwan on Jan-01-2018 15:05 |
|
Hi Helmut,
May be try to change the followings:
Dim minX As Single
minX = m.Min / slotSize * slotSize
Dim maxX As Single
maxX = m.Max / slotSize * slotSize + slotSize
' We can now determine the number of slots
Dim slotCount As Single
slotCount = Int((maxX - minX + 0.5) / slotSize)
to:
Dim minX As Single
minX = Int(m.Min / slotSize) * slotSize
Dim maxX As Single
maxX = Int(m.Max / slotSize) * slotSize + slotSize
' We can now determine the number of slots
Dim slotCount As Long
slotCount = Int((maxX - minX) / slotSize + 0.5)
Regards
Peter Kwan |
|