ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Back ground color (Finance and XYChart)
Posted by icm63 on Apr-19-2020 08:11
Attachments:
For some reason I can not change the color of the back ground of price chart (see attached, white area)

This is my code to build the chart, using Finance Chart and XYChart overlay

The st.backgroundcolor variable is correct, and it transfers ok to functions (I have done an audit of the variables)

Any ideas ??

**********************

        'Background and Border colors to integer
        BackGroundColor = Util.HTMLColorToHex(st.BackGroundColor)
        BackGroundTextColor = Util.HTMLColorToHex(st.BackGroundTextColor)
        BorderColor = Util.HTMLColorToHex(st.BorderColor)
        BorderTextColor = Util.HTMLColorToHex(st.BorderTextColor)


        'Setup Finance chart
        Dim GridColor As Integer
        Select Case st.GridColor
            Case Is = 10 'Light Gray
                GridColor = Util.HTMLColorToHex("#E2E2E2")
            Case Is = 20 'White
                GridColor = Chart.Transparent
            Case Is = 30 'Light Red
                GridColor = Util.HTMLColorToHex("#FFD1D4")
            Case Is = 40 'Light Blue
                GridColor = Util.HTMLColorToHex("#DACEFF")
            Case Is = 50 'Light Orange
                GridColor = Util.HTMLColorToHex("#FFEA84")
            Case Is = 60 'Light Green
                GridColor = Util.HTMLColorToHex("#ABF2B1")
        End Select


        '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)
        mainChart.setData(Period, High, Low, Open, Close, Volume_N, ExtraBars)


        mainChart.setPlotAreaStyle(BackGroundColor, GridColor, GridColor, GridColor, GridColor)
        mainChart.setBackground(BorderColor)
        mainChart.setCustomTextColors(BackGroundTextColor, BorderTextColor)
        mainChart.RTT_setYAxisStyle("normal", 8, BorderTextColor)
        mainChart.setXAxisStyle("normal", 8, BorderTextColor, 0)


        Dim leftAxis As ChartDirector.Axis = Nothing
        Dim HLOCWidth As Integer = 5
        Dim HLOCLineWidth As Integer = 1
        Calc_HLOCDataWidth(High, HLOCWidth, HLOCLineWidth, False)

        Dim ChartHeight As Integer = CInt(FinHeight * (st.Height0 / 100))
        Dim mainXYChart As XYChart = mainChart.addMainChart(ChartHeight)
        mainXYChart.xAxis().setMargin(FC_MinMargin)
        mainXYChart.setClipping()



                HurstCycleSingle(mainChart, mainXYChart, Series, st.Symbol0Period1, st.Symbol0Period2, st.Symbol0Period3, st.Symbol0Period4, GridColor, tempColor0, PublicChartsCutBack, Symbol)
                Dim HLOC As HLOCLayer = mainXYChart.addHLOCLayer(High, Low, Open, Close, &H0, &H0)
                HLOC.setDataWidth(HLOCWidth)
                HLOC.setLineWidth(HLOCLineWidth)
                leftAxis = mainXYChart.addAxis(Chart.Left, 2)
                HLOC.setUseYAxis(leftAxis)





            If leftAxis IsNot Nothing Then
                leftAxis.setColors(&H0, BorderTextColor, BorderTextColor, &H0)
            End If
SH_0019.png

  Re: Back ground color (Finance and XYChart)
Posted by Peter Kwan on Apr-20-2020 02:02
Hi icm63,

I started with the Finance Chart (2) sample code that comes with ChartDirector, and I added the line:

c.setPlotAreaStyle(&Hff99ff, &Hdddddd, &Hdddddd, &Hdddddd, &Hdddddd)

and the above works normally.

For your case, for testing, please use hard coded colors:

mainChart.setPlotAreaStyle(&Hff99ff, &Hdddddd, &Hdddddd, &Hdddddd, &Hdddddd)

If hard coded colors work, but your original code does not work, that means the variables used in your code is not the same as the hard coded colors.

If even hard coded colors do not work, some possibilities are:

- There may be another line of code that changes the plotarea color back to white.

- I noted that your FinanceChart may have been modified. For example, it has the  setCustomTextColors and RTT_setYAxisStyle methods, which are not in the original ChartDirector FinanceChart. May be the modifications affects the plotarea background color.

If the above still does not solve the problem, is it possible to create a complete example that can reproduce the problem with hard coded colors (such as by modifying the "Finance Chart (2)" sample code to reproduce the problem)?

Regards
Peter Kwan

  Re: Back ground color (Finance and XYChart)
Posted by icm63 on Apr-20-2020 03:23
What routines can override the painting of 'setPlotAreaStyle' back ground color? Using another XYchart layer?

.setBackGround ?? Maybe

Any others ?

  Re: Back ground color (Finance and XYChart)
Posted by icm63 on Apr-20-2020 03:44
Fixed it

This is how it should have been (I had adjusted the addMainChart function)

    'Set Finance Chart as XYChart and OHLC layer
        mainXYChart = mainChart.addMainChart(FinHeight, BackGroundColor)
        mainXYChart.setBackground(BorderColor)
        mainXYChart.getLegend.setKeySpacing(5)

  Re: Back ground color (Finance and XYChart)
Posted by Peter Kwan on Apr-20-2020 20:26
Hi icm63,

If you look at the original FinanceChart source code (this is included in the download), you can see that the FinanceChart.setPlotAreaStyle, it just stores the background color into a member variable m_plotAreaBgColor. It does not actually do anything other than storing the colors.

Later, when you add the main chart or any kind of indicator chart, the FinanceChart will use m_plotAreaBgColor as the plotarea background color of the chart (by calling XYChart.setPlotArea). This is the only place that uses the m_plotAreaBgColor variable. Note that setPlotAreaStyle only affects charts that are added after calling the method. If you call addMainChart first, then call setPlotAreaStyle, it will have no effect to the main chart.

Some other APIs can change the plotarea background include:

PlotArea.setBackground
PlotArea.setBackground2
PlotArea.setAltBgColor
PlotArea.set4QBgColor

XYChart.setBackground only changes the XYChart background. It does not change the plotarea background.

Regards
Peter Kwan