/* Copyright (c) 2008-2024 Jan W. Krieger () This software is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License (LGPL) for more details. You should have received a copy of the GNU Lesser General Public License (LGPL) along with this program. If not, see . */ #ifndef jkqtpfinancial_H #define jkqtpfinancial_H #include #include #include #include "jkqtplotter/jkqtptools.h" #include "jkqtplotter/jkqtplotter_imexport.h" #include "jkqtplotter/jkqtpgraphsbase.h" #include "jkqtplotter/jkqtpgraphsbasestylingmixins.h" /** \brief This class draws an Open-High-Low-Close (OHLC) or candle-stick graph typically representing financial data * \ingroup jkqtplotter_financialgraphs * * This graph draws either candlstick charts: * \image html financialgraphs_basics_candlestick.png * or Open-High-Low-Close (OHLC) charts (depending on what you set in setGraphType() ). * \image html financialgraphs_basics_ohlc.png * * Here is an example graph showcasing both variants: * * \image html JKQTPFinancialGraph.png * * \see For details on the graph types see https://en.wikipedia.org/wiki/Candlestick_chart and https://en.wikipedia.org/wiki/Open-high-low-close_chart * \see JKQTPXGraph * * * \section JKQTPFinancialGraphStyling Styling the Financial Graphs * You can control the type of graph and it's appearance with these functions (example images are in the documentation of the functions): * - setGraphType() * - setCandlestickTwoColor() * - setCandlestickOneColor() * - setOHLCTwoColor() * . * * For fine-tuning, you can access the line- and fill-styles for positiove (close>open) and negative (closeopen) * \param cNegative color for negative items (closeopen) * \param fillPositive fill-color for positive items (close>open) * \param lineNegative line-color for negative items (closeopen) * \param cNegative color for negative items (closesetCandlestickTwoColor(QColor("blue"), QColor("orange")): * * \image html JKQTPFinancialGraphSetCandlestickTwoColor.png */ void setCandlestickTwoColor(QColor cPositive, QColor cNegative); /** \brief sets graphType = FinancialGraphType::CandleStick and sets the positive and negative fill color and a single line-color * * \param cPositive color for fill of positive items (close>open) * \param cNegative color for fill of negative items (closesetCandlestickTwoColor(QColor("green"), QColor("red"), QColor("black")): * * \image html JKQTPFinancialGraphSetCandlestickTwoColor2.png */ void setCandlestickTwoColor(QColor cPositive, QColor cNegative, QColor lineCOlor); /** \brief sets graphType = FinancialGraphType::CandleStick and sets one color \a cLine for positive and negative items, where positive items are unfilled and negative items are filled * * \param cLine line-color for all items and also fill-color for positive items (close>open), negative items are unfilled * * Here is an example output for setCandlestickOneColor(QColor("black")): * * \image html JKQTPFinancialGraphSetCandlestickOneColor.png */ void setCandlestickOneColor(QColor cLine); /** \brief sets graphType = FinancialGraphType::OHLC and sets the positive and negative color (for fill and line equal!) * * \param cPositive color for positive items (close>open) * \param cNegative color for negative items (closesetOHLCTwoColor(QColor("darkblue"), QColor("darkorange")): * * \image html JKQTPFinancialGraphSetOHLCTwoColor.png */ void setOHLCTwoColor(QColor cPositive, QColor cNegative); /** \copydoc openColumn */ void setOpenColumn(int __value); /** \copydoc openColumn */ void setOpenColumn (size_t __value); /** \copydoc closeColumn */ void setCloseColumn(int __value); /** \copydoc closeColumn */ void setCloseColumn (size_t __value); /** \copydoc highColumn */ void setHighColumn(int __value); /** \copydoc highColumn */ void setHighColumn (size_t __value); /** \copydoc lowColumn */ void setLowColumn(int __value); /** \copydoc lowColumn */ void setLowColumn (size_t __value); protected: static QSet parentsAlreadySeen; /** \brief type of the financial graph (OHLC or candle-stick) * * \see setGraphType(), getGraphType(), FinancialGraphType */ FinancialGraphType graphType; /** \brief column for the "Open" value of the financial graph * * \see setOpenColumn(), getOpenColumn() */ int openColumn; /** \brief column for the "Close" value of the financial graph * * \see setCloseColumn(), getCloseColumn() */ int closeColumn; /** \brief column for the "High" value of the financial graph * * \see setHighColumn(), getHighColumn() */ int highColumn; /** \brief column for the "Low" value of the financial graph * * \see setLowColumn(), getLowColumn() */ int lowColumn; /** \brief the width of the boxes, relative to the distance between the current and the next x-value * * See the following graphic to understand this concept (same principle as described in the JKQTPBarGraphBase documentation): * \image html financialgraphs_shiftwidth.png */ double width; /** \brief the shift of the boxes, relative to the distance between the current and the next x-value * * See the following graphic to understand this concept (same principle as described in the JKQTPBarGraphBase documentation): * \image html financialgraphs_shiftwidth.png */ double shift; /** \brief fill style for positive items (close>open) * * \see fillStylePositive() */ JKQTPGraphFillStyleMixin m_fillStylePositive; /** \brief fill style for negative items (closeopen) * * \see lineStylePositive() */ JKQTPGraphLineStyleMixin m_lineStylePositive; /** \brief fill style for negative items (close