|
Expanded TOP Axis breaks Layout() |
Posted by icm63 on Aug-20-2021 11:54 |
|
Posted a two charts
1) A control test
2) A chart show an error, new top XAxis, with pink lines not drawing from the start point
I have a HARD CODED variable for TOP MARGIN like this (VB.net)
Dim FC_topMargin As Integer = 28
When I want to test the chart to include top xAxis I change in the code the above to
Dim FC_topMargin As Integer = 65
When I do that the pink lines fail to draw from the start point. Lines draw after layout is called.
The chart is mostly based on your FINANCE CHART code.
Dim FC_leftMargin As Integer = 40
Dim FC_rightMargin As Integer = 40
Dim FC_topMargin As Integer = <as above>
Dim FC_bottomMargin As Integer = 30
'Setup Finance chart
Dim mainChart As cFinanceChart = New cFinanceChart(st.PlotWidth + FC_leftMargin + FC_rightMargin + FC_MinMargin)
mainChart.setMargins(FC_leftMargin, FC_topMargin, FC_rightMargin, FC_bottomMargin)
Dim FinHeight As Integer = st.PlotHeight + FC_topMargin
mainXYChart = mainChart.addMainChart(FinHeight)
QUESTION: Where do you think I should look to find the error? I have spent a few hours on it with no luck.
|
Re: Expanded TOP Axis breaks Layout() |
Posted by Peter Kwan on Aug-20-2021 16:23 |
|
Hi icm63.
My wild guess is that the line "Dim FinHeight As Integer = st.PlotHeight + FC_topMargin" is incorrect. It should be:
Dim FinHeight As Integer = st.PlotHeight
The margins are the space outside the plot area, while the height in addMainPrice is the height of the plot area.
In your original code, the margin is applied to both the region outside the plot area as the margin. It also increases the height of the plot area. You can use an image editor to measure the height of the plot area, and you can see they are different and they differ by the FC_topMargin.
In your first chart, there is a line at y = 160. In the second chart, the same line appears at y = 154. It is as if the code that draws the line uses st.PlotHeight as the plot area height, but in your code it is st.PlotHeight + FC_topMargin. If my guess is correct, changing the height to st.PlotHeight should solve the problem.
Regards
Peter Kwan |
Re: Expanded TOP Axis breaks Layout() |
Posted by icm63 on Aug-21-2021 03:46 |
|
NO luck with that fix.
I wish to have dates below and above price and indicator charts
This is how I add the above dates (via xAxis2)
Dim xTopAxis As ChartDirector.Axis = Nothing
If ChartxAxisTopOn = 20 Then
mainXYChart.xAxis2().copyAxis(mainXYChart.xAxis())
xTopAxis = mainXYChart.xAxis2()
xTopAxis.setIndent(True)
xTopAxis.setTickLength(2, 0)
xTopAxis.setColors(Chart.Transparent, BorderTextColor, BorderTextColor, BorderTextColor)
xTopAxis.setLabelStyle("normal", 8, BorderTextColor, 0)
End If
Its very strange how code works for the first chart and not the second, all I did was change top margin width, and add xAxis2
QUESTION: Is there a way to have two xAxis, one below the top price chart, and a another below all the lower indicators (default, xAxis). |
Re: Expanded TOP Axis breaks Layout() |
Posted by icm63 on Aug-21-2021 09:03 |
|
GOAL In a finance chart, with many indicators, to have a xAxis after the first main chart and maintain the default xAxis on the bottom.
How to do this: Create a dummy XYChart (Height = 0) and add it after the main chart and show the xAxis Date . Then all indicators are added after this.
************************************
It requires some re building of this indicator add
Public Function addIndicator(ByVal height As Integer, Optional ByVal CustomBackGroundColor As Integer = &HFFFFFF) As XYChart
'create a new chart object
Dim ret As New XYChart(m_totalWidth, height + m_topMargin + m_bottomMargin, Chart.Transparent)
ret.setTrimData(m_extraPoints)
If m_currentChart IsNot Nothing Then
'if there is a chart before the newly created chart, disable its x-axis, and copy
'its x-axis labels to the new chart
m_currentChart.xAxis().setColors(Chart.Transparent, Chart.Transparent)
ret.xAxis().copyAxis(m_currentChart.xAxis())
'add chart to MultiChart and update the total height
addChart(0, m_totalHeight + m_plotAreaGap, ret)
m_totalHeight = m_totalHeight + height + 1 + m_plotAreaGap
Else
'no existing chart - create the x-axis labels from scratch
setXLabels(ret.xAxis())
'add chart to MultiChart and update the total height
addChart(0, m_totalHeight, ret)
m_totalHeight = m_totalHeight + height + 1
End If
'the newly created chart becomes the current chart
m_currentChart = ret
'update the size
setSize(m_totalWidth, m_totalHeight + m_topMargin + m_bottomMargin)
'configure the plot area
ret.setPlotArea(m_leftMargin, m_topMargin, m_totalWidth - m_leftMargin - m_rightMargin, height, CustomBackGroundColor, -1, _
m_plotAreaBorder).setGridColor(m_majorHGridColor, m_majorVGridColor, m_minorHGridColor, m_minorVGridColor)
ret.setAntiAlias(m_antiAlias)
'configure legend box
Dim box As LegendBox = ret.addLegend(m_leftMargin, m_topMargin, False, m_legendFont, m_legendFontSize)
box.setFontColor(m_legendFontColor)
box.setBackground(m_legendBgColor)
box.setMargin2(5, 0, 2, 1)
box.setSize(m_totalWidth - m_leftMargin - m_rightMargin + 1, 0)
'configure x-axis
Dim a As Axis = ret.xAxis()
a.setIndent(True)
a.setTickLength(2, 0)
a.setColors(Chart.Transparent, m_xAxisFontColor, m_xAxisFontColor, m_xAxisFontColor)
a.setLabelStyle(m_xAxisFont, m_xAxisFontSize, m_xAxisFontColor, m_xAxisFontAngle)
'configure y-axis
ret.setYAxisOnRight(m_axisOnRight)
configureYAxis(ret.yAxis(), height)
Return ret
End Function
******************************
Any ideas? |
Re: Expanded TOP Axis breaks Layout() |
Posted by icm63 on Aug-23-2021 08:13 |
|
I have cracked it, ignore this request |
|