ChartDirector 7.0 (Python Edition)

FinanceChart


FinanceChart is a financial charting library built on top of the main ChartDirector library. It extends MultiChart by implementing many financial indicators, and allowing complex financial charts to be composed easily.

Key Features

Using FinanceChart

To use FinanceChart, you need to include the FinanceChart module using:

from FinanceChart.py import *

You may then create an instance of FinanceChart. Next, you may add data to it using setData. After that, you may add the main chart (addMainChart) and other indicator charts to display the data graphically. These charts may be added in any order.

For the main chart, you may:

For indicator charts, FinanceChart includes a wide variety of indicators. Please refer to the table below for details. You may also add your own custom indicator chart using addLineIndicator and addBarIndicator.

In addition to chart building methods, FinanceChart also has a number of chart formatting methods, such as addPlotAreaTitle to add chart title, setPlotAreaStyle to control background color and grid lines, setDateLabelFormat to control date/time formatting, etc.

Furthermore, as FinanceChart is a subclass of MultiChart, and the main and indicator charts are implemented as XYChart objects, they can use the powerful ChartDirector API for formatting (eg. background images, custom logos, custom text boxes, metallic colors, etc).

FinanceChart Source Code

To serve as an example of how to build an application specific chart library on top of ChartDirector, the source code of FinanceChart is opened. It is in the "ChartDirector/lib" directory.

FinanceChart Methods

MethodInheritedDescription
FinanceChart(Self)Creates a new FinanceChart object.
enableAntiAlias(Self)Enables/Disables anti-alias.
setMargins(Self)Sets the margins around the plot area. The default is 40 pixels for the left and right margins, and 30 pixels for the top margin and 35 pixels for the bottom margin.
addPlotAreaTitle(Self)Adds a text title above the plot area. You may add multiple title above the plot area by calling this method multiple times.
setPlotAreaStyle(Self)Sets the plot area background and grid colors. The default is a white background with light grey (DDDDDD) grid lines.
setPlotAreaBorder(Self)Sets the plot area border color and the gap distance between charts. The default is a grey (888888) border with two 2 pixels gap between charts.
setLegendStyle(Self)Sets legend font style and background color. The default is Arial 8 pt black font on a semi-transparent light grey (80CCCCCC) background.
setXAxisStyle(Self)Sets x-axis label style. The default is Arial 8 pt black color as font with no text rotation.
setYAxisStyle(Self)Sets y-axis label style. The default is Arial 8 pt black color, with 14 pixels margin.
setAxisOnRight(Self)Sets whether the main y-axis is on right of left side of the plot area. The default is on right.
setLogScale(Self)Determines if log scale should be used for the main chart. The default is to use linear scale.
setPercentageAxis(Self)Label the axis of the main chart in percentage unit.
setDateLabelFormat(Self)Sets the date/time formats to use for the x-axis labels under various cases.
setDateLabelSpacing(Self)Sets the minimum label spacing between two labels on the time axis.
setToolTipDateFormat(Self)Sets the date/time formats to use for the tool tips under various cases.
getToolTipDateFormat(Self)Gets the date/time format string to use for tool tips.
setNumberLabelFormat(Self)Sets the number format to use.
setData(Self)Sets the data to be used in the chart.
addMainChart(Self)Adds the main chart - the chart that shows the data for the prices.
addCandleStick(Self)Adds a candlestick layer to the main chart.
addHLOC(Self)Adds a HLOC layer to the main chart.
addCloseLine(Self)Adds a closing price line on the main chart.
addWeightedClose(Self)Adds a weighted close line on the main chart.
addTypicalPrice(Self)Adds a typical price line on the main chart.
addMedianPrice(Self)Adds a median price line on the main chart.
addComparison(Self)Adds a data series to the main chart for comparison with the closing price.
addSimpleMovingAvg(Self)Adds a simple moving average line on the main chart.
addExpMovingAvg(Self)Adds an exponential moving average line on the main chart.
addTriMovingAvg(Self)Adds a triangular moving average line on the main chart.
addWeightedMovingAvg(Self)Adds a weighted moving average line on the main chart.
addParabolicSAR(Self)Adds a parabolic SAR indicator to the main chart.
addBand(Self)Adds a generic band to the main finance chart. This method is used internally by other methods to add various bands (eg. Bollinger band, Donchian channels, etc).
addBollingerBand(Self)Adds a Bollinger band to the main chart.
addDonchianChannel(Self)Adds a Donchian channel to the main chart.
addEnvelop(Self)Adds a price envelop to the main chart. The price envelop is a defined as a ratio around a moving average. For example, a ratio of 0.2 means 20% above and below the moving average.
addVolBars(Self)Adds a volume bar chart layer on the main chart.
addIndicator(Self)Adds a blank indicator chart to the finance chart. Used internally to add other indicators. Override to change the default formatting (eg. axis fonts, etc.) of the various indicators.
addLineIndicator(Self)Adds a generic line indicator chart.
addLineIndicator2(Self)Adds a line to an existing indicator chart.
addBarIndicator(Self)Adds a generic bar indicator chart.
addBarIndicator2(Self)Adds a bar layer to an existing indicator chart.
addThreshold(Self)Adds an upper/lower threshold range to an existing indicator chart.
addAccDist(Self)Adds an Accumulation/Distribution indicator chart.
addAroon(Self)Adds an Aroon Up/Down indicators chart.
addAroonOsc(Self)Adds an Aroon Oscillator indicator chart.
addADX(Self)Adds an Average Directional Index indicators chart.
addATR(Self)Adds an Average True Range indicators chart.
addBollingerWidth(Self)Adds a Bollinger Band Width indicator chart.
addCCI(Self)Adds a Community Channel Index indicator chart.
addChaikinMoneyFlow(Self)Adds a Chaikin Money Flow indicator chart.
addChaikinOscillator(Self)Adds a Chaikin Oscillator indicator chart.
addChaikinVolatility(Self)Adds a Chaikin Volatility indicator chart.
addCLV(Self)Adds a Close Location Value indicator chart.
addDPO(Self)Adds a Detrended Price Oscillator indicator chart.
addDonchianWidth(Self)Adds a Donchian Channel Width indicator chart.
addEaseOfMovement(Self)Adds a Ease of Movement indicator chart.
addFastStochastic(Self)Adds a Fast Stochastic indicator chart.
addMACD(Self)Adds a MACD indicator chart.
addMassIndex(Self)Adds a Mass Index indicator chart.
addMFI(Self)Adds a Money Flow Index indicator chart.
addMomentum(Self)Adds a Momentum indicator chart.
addNVI(Self)Adds a Negative Volume Index indicator chart.
addOBV(Self)Adds an On Balance Volume indicator chart.
addPerformance(Self)Adds a Performance indicator chart.
addPPO(Self)Adds a Percentage Price Oscillator indicator chart.
addPVI(Self)Adds a Positive Volume Index indicator chart.
addPVO(Self)Adds a Percentage Volume Oscillator indicator chart.
addPVT(Self)Adds a Price Volume Trend indicator chart.
addROC(Self)Adds a Rate of Change indicator chart.
addRSI(Self)Adds a Relative Strength Index indicator chart.
addSlowStochastic(Self)Adds a Slow Stochastic indicator chart.
addStdDev(Self)Adds a Moving Standard Deviation indicator chart.
addStochRSI(Self)Adds a Stochastic RSI indicator chart.
addTRIX(Self)Adds a TRIX indicator chart.
addUltimateOscillator(Self)Adds an Ultimate Oscillator indicator chart.
addVolIndicator(Self)Adds a Volume indicator chart.
addWilliamR(Self)Adds a William %R indicator chart.
MultiChartMultiChartCreates a new MultiChart object.
addChartMultiChartAdds a BaseChart object (or its subclass such as PieChart, XYChart, PolarChart, AngularMeter or LinearMeter) into the multi-chart.
getChartMultiChartGets the specified chart in the MultiChart.
getChartCountMultiChartGets the number of charts in the MultiChart.
setMainChartMultiChartSets the chart that provides the plot area for plot area features.
setSizeBaseChartSets the size of the chart, exclusive of the drop shadow (if any).
getWidthBaseChartGets the width of the chart.
getHeightBaseChartGets the height of the chart.
getAbsOffsetXBaseChartGets the x offset of the chart relative to the outermost MultiChart container.
getAbsOffsetYBaseChartGets the y offset of the chart relative to the outermost MultiChart container.
setBackgroundBaseChartSets the background color, border color and 3D border effect of the chart.
setRoundedFrameBaseChartSets the border style of the chart to rounded corners.
setThickFrameBaseChartSets a thick frame around the chart.
setDropShadowBaseChartAdds a drop shadow to the chart.
setBorderBaseChartSets the border color of the chart.
setWallpaperBaseChartUses the image from the specified file or resource as the wallpaper to fill the background of the chart.
setBgImageBaseChartUses the image from the specified file or resource as the background image of the chart.
setSearchPathBaseChartSets the search path for loading image files.
setResourceBaseChartAssigns a resource ID to a DrawArea object to allow it to be referenced using a resource path.
setTransparentColorBaseChartSpecifies a certain color to mean transparent when creating a raster image output.
setAntiAliasBaseChartControls whether anti-alias is used when drawing lines, shapes and text.
addTitleBaseChartAdds a title at the top center of the chart.
addTitle2BaseChartAdds a title to the chart.
addLegendBaseChartAdds a legend box to the chart.
addLegend2BaseChartAdds a legend box to the chart with grid layout.
getLegendBaseChartGets the LegendBox object representing the legend box in the chart.
layoutLegendBaseChartLays out and gets the LegendBox object representing the legend box in the chart.
getDrawAreaBaseChartRetrieves the internal DrawArea object that is used to draw the chart.
addTextBaseChartAdds a text box to the chart.
addTableBaseChartAdds a CDML table to the chart.
addLineBaseChartAdds a line to the chart.
addExtraFieldBaseChartAdds an array of text to be used as an extra field in various places.
addExtraField2BaseChartAdds an array of numbers/dates to be used as an extra field in various places.
setColorBaseChartChange the color at the specified position in the palette.
setColorsBaseChartChange the colors in the palette.
setColors2BaseChartChange the colors in the palette, starting from the specified position in the palette.
getColorBaseChartGets the color at the specified position of the palette.
adjustBrightnessBaseChartCreates a color that is a darkened or brightened version of the given color.
halfColorBaseChartCreates a color that is half the intensity of the given color.
dashLineColorBaseChartCreates a dash line color.
patternColorBaseChartCreates a pattern color using an array of colors as the bitmap pattern.
patternColor2BaseChartCreates a pattern color by using the image from the specified file or resource as the pattern.
linearGradientColorBaseChartCreates a two-point linear gradient color.
linearGradientColor2BaseChartCreates a multi-point linear gradient color.
radialGradientColorBaseChartCreates a two-point radial gradient color.
radialGradientColor2BaseChartCreates a multi-point radial gradient color.
gradientColorBaseChartCreates a two-point linear gradient color.
gradientColor2BaseChartCreates a multi-point linear gradient color.
setDefaultFontsBaseChartSets the defaults for normal, bold, italic and bold-italic fonts.
setFontTableBaseChartSets an entry in the font table to the specified font name.
formatValueBaseChartFormats a number/date using the ChartDirector formatting syntax as is in Parameter Substitution and Formatting.
setNumberFormatBaseChartSets the characters used for thousand separator, decimal point, and negative sign.
setMonthNamesBaseChartSets the names of the months for date/time formatting purposes.
setWeekDayNamesBaseChartSets the names of the week days for date/time formatting purposes.
setAMPMBaseChartSets the names to be used to denote morning and afternoon.
layoutBaseChartPerform auto-scaling of the axes (if any) and compute the positions of the various objects in the chart.
enableVectorOutputBaseChartThis method is deprecated. It has no effect and may be removed in future versions of ChartDirector.
setOutputOptionsBaseChartSets output format options for the next chart output.
makeChartBaseChartGenerates the chart image and save it into a file.
makeChart2BaseChartGenerates the chart as an image in memory.
makeChart3BaseChartGenerates the chart in internal format and return a DrawArea object to allow adding custom drawings on top of the chart.
makeTmpFileBaseChartGenerates the chart as an image and save it to a temporary file, and automatically remove old files.
initDynamicLayerBaseChartInitializes a dynamic layer for drawing text and shapes.
removeDynamicLayerBaseChartRemoves the dynamic layer if any.
getHTMLImageMapBaseChartGenerates an HTML image map to define hot spots and tooltips for the chart.