Chart(星盤)
Introduction
A Zi Wei Dou Shu(紫微斗數) chart, also called a natal chart(命盤), consists of twelve palaces and a central palace. Each palace’s Earthly Branch(地支) is fixed. The sequence begins with yin(寅), rather than zi(子), because the first lunar month corresponds to Yin(寅)—the convention called the first lunar month corresponds to yin(正月建寅). In iztro, yin palace(寅宮) has index 0, mao palace(卯宮) has index 1, and the remaining positions continue clockwise, as shown below:
si(巳)3 | woo(午)4 | wei(未)5 | shen(申)6 |
chen(辰)2 | central palace | you(酉)7 | |
mao(卯)1 | xu(戌)8 | ||
yin(寅)0 | chou(丑)11 | zi(子)10 | hai(亥)9 |
The central palace can display whatever information you choose and generally does not affect the chart’s interpretation. The surrounding twelve palaces(十二宮) hold stars(星曜), the four transformations(四化), fortune periods(運限), palace names, and other data. See palaces for more on palaces(宮位); this page focuses on the chart. A chart consists of palaces and stars. If these concepts are new to you, start with the basics.
After installing iztro, use the following code to import the chart module (astro) object. For iztro installation instructions, see Install iztro.
astro static methods
Use import to bring the object into your code before calling its static methods.
import { astro } from "iztro";Chart configuration and input validation ^2.6.2
Charts returned by bySolar, byLunar, and withOptions retain the configuration and language used at creation. Changing global defaults or creating charts in other languages does not change an existing chart’s fortune-period(運限) or four-transformation(四化) analysis.
In withOptions, type is optional and defaults to the solar calendar; config overrides settings for that chart only. Chart-generation and date-helper methods default language to zh-CN when omitted, and choosing a language does not affect other calls. Supported values are zh-CN, zh-TW, en-US, ja-JP, ko-KR, and vi-VN.
The year must be from 1 to 9999, and the date must exist in the solar or lunar calendar. Date strings accept hyphens, slashes, or dots as separators and may include HH:mm or HH:mm:ss. Historical solar dates follow the underlying calendar’s Julian/Gregorian transition rules. Time indices must be integers from 0 to 12. Unknown gender, language, date type, or chart type, and non-boolean leap-month options, throw errors. Lunar dates are validated against the actual month length; isLeapMonth: true is ignored for a month with no leap counterpart.
See Configuration and plugins for configuration scope, the independent copy returned by getConfig(), and resetConfig().
astrolabeBySolarDate deprecated
This method was deprecated in v2.0.5. Use bySolar instead; parameters and return values are unchanged.
bySolar ^2.0.5
Purpose
Generates a chart from a solar-calendar date.
Definition
tsexport type bySolar = ( solarDateStr: string, timeIndex: number, gender: GenderName, fixLeap: boolean = true, language: Language = "zh-CN" ) => FunctionalAstrolabe;Parameters
Parameter Type Required? Default value Description solarDateStr stringtrue- Gregorian date【YYYY-M-D】 timeIndex numbertrue- Birth-hour index [0–12], from early Zi hour (0) to late Zi hour (12) gender GenderNametrue- Gender【Male/Female】 fixLeap booleanfalsetrueWhether to adjust leap months. If true, the first half is assigned to the preceding month and the second half to the following month.language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.bySolar("2000-8-16", 2, "女", true, "zh-CN");
astrolabeByLunarDate deprecated
This method was deprecated in v2.0.5. Use byLunar instead; parameters and return values are unchanged.
byLunar ^2.0.5
Purpose
Generates a chart from a lunar-calendar date. The author recommends using
bySolardirectly, since this method first converts the lunar date to a solar date and then callsbySolarfor the result.Definition
tsexport type byLunar = ( lunarDateStr: string, timeIndex: number, gender: GenderName, isLeapMonth: boolean = false, fixLeap: boolean = true, language?: Language ) => FunctionalAstrolabe;Parameters
Parameter Type Required? Default value Description lunarDateStr stringtrue- Lunar date [YYYY-M-D]. For lunar year 2000, month 7, day 17, pass2000-7-17.timeIndex numbertrue- Birth-hour index [0–12], from early Zi hour (0) to late Zi hour (12) gender GenderNametrue- Gender【Male/Female】 isLeapMonth booleanfalsefalseWhether the supplied lunar month is a leap month; ignored if that month has no leap counterpart. fixLeap booleanfalsetrueWhether to adjust leap months. If true, the first half is assigned to the preceding month and the second half to the following month.language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.byLunar("2000-8-16", 2, "女", false, true, "zh-CN");
withOptions ^2.4.1
Purpose
Generates chart data through a convenient wrapper around
bySolarandbyLunar.Definition
tstype Option = { type?: 'solar' | 'lunar'; dateStr: string; timeIndex: number; gender: GenderName; isLeapMonth?: boolean; fixLeap?: boolean; language?: Language; config?: Config; astroType?: AstroType; }; export type withOptions = ( option: Option ) => FunctionalAstrolabe;Parameters
Parameter Type Required? Default value Description type solar|lunarfalsesolardate type dateStr stringtrue- Date of birth in YYYY-M-D format timeIndex numbertrue- Birth-hour index [0–12], from early Zi hour (0) to late Zi hour (12) gender GenderNametrue- Gender【Male/Female】 isLeapMonth booleanfalsefalseWhether the supplied lunar month is a leap month; ignored if that month has no leap counterpart. fixLeap booleanfalsetrueWhether to adjust leap months. If true, the first half is assigned to the preceding month and the second half to the following month.language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.config Configfalse- Overrides the brightness, four transformations and time-boundary settings only for the chart being created (^2.6.2). astroType ^2.5.0 AstroTypefalseheavenChart type. Used to select the natal, earth or human chart only when config.algorithmiszhongzhou.Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.withOptions({ type: 'solar', dateStr: '1999-12-29', timeIndex: 2, gender: 'female', isLeapMonth: false, fixLeap: true, language: 'zh-CN', config: { algorithm: 'zhongzhou' }, astroType: 'earth' })Tips
astroTypeacceptsheaven,earth, orhuman. The defaultheavenis the Heaven Chart(天盤).earthuses the body palace(身宮) as the soul palace(命宮), whilehumanuses the spirit palace(福德宮) as the soul palace. SeeAstroType.
getMajorStarBySolarDate ^1.2.1
Purpose
Retrieves the soul palace’s(命宮) major stars from a solar-calendar date.
Definition
tstype getMajorStarBySolarDate = ( solarDateStr: string, timeIndex: number, fixLeap: boolean = true, language?: Language, ) => string;Parameters
Parameter Type Required? Default value Description solarDateStr stringtrue- Gregorian date【YYYY-M-D】 timeIndex numbertrue- Birth-hour index [0–12], from early Zi hour (0) to late Zi hour (12) fixLeap booleanfalsetrueWhether to adjust leap months. If true, the first half is assigned to the preceding month and the second half to the following month.language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Example
tsimport { astro } from 'isztro'; const result = getMajorStarBySolarDate('2023-4-7', 0);
getMajorStarByLunarDate ^1.2.1
Purpose
Retrieves the soul palace’s(命宮) major stars from a lunar-calendar date.
Definition
tstype getMajorStarByLunarDate = ( lunarDateStr: string, timeIndex: number, isLeapMonth: boolean = false, fixLeap: boolean = true, language?: Language, ) =>Parameters
Parameter Type Required? Default value Description lunarDateStr stringtrue- Lunar date [YYYY-M-D]. For lunar year 2000, month 7, day 17, pass2000-7-17.timeIndex numbertrue- Birth-hour index [0–12], from early Zi hour (0) to late Zi hour (12) isLeapMonth booleanfalsefalseWhether the supplied lunar month is a leap month; ignored if that month has no leap counterpart. fixLeap booleanfalsetrueWhether to adjust leap months. If true, the first half is assigned to the preceding month and the second half to the following month.language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Example
tsimport { astro } from 'isztro'; const result = getMajorStarByLunarDate('2023-2-17', 0, true, false);
getSignBySolarDate ^1.2.1
Purpose
Retrieves the Western zodiac sign from a solar-calendar date.
Definition
tstype getSignBySolarDate = ( solarDateStr: string, language?: Language ) => string;Parameters
Parameter Type Required? Default value Description solarDateStr stringtrue- Gregorian date【YYYY-M-D】 language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Example
tsimport { astro } from 'isztro'; const result = getSignBySolarDate('2023-9-5');
getSignByLunarDate ^1.2.1
Purpose
Retrieves the Western zodiac sign from a lunar-calendar date.
Definition
tstype getSignByLunarDate = ( lunarDateStr: string, isLeapMonth?: boolean, language?: Language ) => string;Parameters
Parameter Type Required? Default value Description lunarDateStr stringtrue- Lunar date [YYYY-M-D]. For lunar year 2000, month 7, day 17, pass2000-7-17.isLeapMonth booleanfalsefalseWhether the supplied lunar month is a leap month; ignored if that month has no leap counterpart. language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Example
tsimport { astro } from 'isztro'; const result = getSignByLunarDate('2023-7-21');
getZodiacBySolarDate ^1.2.1
Purpose
Retrieves the Chinese zodiac animal from a solar-calendar date.
Definition
tstype getZodiacBySolarDate = (solarDateStr: string, language?: Language) => string;Parameters
Parameter Type Required? Default value Description solarDateStr stringtrue- Gregorian date【YYYY-M-D】 language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Example
tsimport { astro } from 'isztro'; const result = getZodiacBySolarDate('2023-2-20');
getZodiacByLunarYear ^1.2.1
Purpose
Retrieves the Chinese zodiac animal for a lunar-calendar year.
Definition
tstype getZodiacByLunarYear = (year: number, language?: Language) => string;Parameters
Parameter Type Required? Default value Description year numbertrue- Lunar-calendar year language Languagefalsezh-CNThe returned data uses the specified language. Supported values are zh-CN,zh-TW,en-US,ko-KR,ja-JP, andvi-VN.Example
tsimport { astro } from 'isztro'; const result = getZodiacByLunarYear(2023);
Classes and analysis methods
Development suggestions
Use astro’s static methods to obtain data rather than constructing FunctionalAstrolabe manually.
FunctionalAstrolabe
implements
IFunctionalAstrolabe extends AstrolabeThis class inherits its properties from Astrolabe and adds methods for chart analysis. bySolar() and byLunar() return instances of this class.
Interface definition
tsinterface IFunctionalAstrolabe extends Astrolabe { toJSON: () => Astrolabe; use(plugin: Plugin): void; horoscope: (date?: string | Date, timeIndex?: number) => Horoscope; decadalList: () => DecadalHoroscope[]; yearlyList: (indexOrName: number | PalaceName) => YearlyHoroscope[]; monthlyList: (year: number, fixLeap?: boolean) => MonthlyHoroscope[]; palace: (indexOrName: number | PalaceName) => IFunctionalPalace | undefined; surroundedPalaces: (indexOrName: number | PalaceName) => SurroundedPalaces; isSurrounded: ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean; isSurroundedOneOf: ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean; notSurrounded: ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean; hasMutagenInSurroundedPalace: ( indexOrName: number | PalaceName, mutagen: Mutagen ) => boolean; hasMutagenInOppositePalace: ( indexOrName: number | PalaceName, mutagen: Mutagen ) => boolean; }Properties
Reference Astrolabe
Methods
toJSON() ^2.6.0
Purpose
Converts the functional chart to a plain JSON object. Analysis methods, plugin functions, and runtime references are excluded; circular references are safely ignored.
Definition
tstype toJSON = () => Astrolabe;Parameters
None
Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.bySolar("2000-8-16", 2, "女"); const data = astrolabe.toJSON();
use() ^2.3.0
Purpose
Applies a plugin to the current chart instance. Unlike
astro.loadPlugin(),use()affects only this instance.Definition
tstype use = (plugin: Plugin) => void;Parameters
Parameter Type Required? Default value Description plugin Plugintrue- Plugin function to apply to the current chart Return value
voidExample
tsimport { astro, FunctionalAstrolabe } from "iztro"; interface IAstrolabe extends FunctionalAstrolabe { soulPalaceName: () => string; } function soulPalacePlugin(this: IAstrolabe) { this.soulPalaceName = () => this.palace("命宫")?.name ?? ""; } const astrolabe = astro.bySolar<IAstrolabe>("2000-8-16", 2, "女"); astrolabe.use(soulPalacePlugin); const name = astrolabe.soulPalaceName();
horoscope() ^0.2.0
Purpose
Retrieves fortune-period(運限) data. To calculate it for the current moment, omit all arguments; the method uses the system time at the call.
Note
- If
dateis a date-only string inYYYY-M-Dformat andtimeIndexis omitted, the time used fordateisearly Zi houron that date, for thehourly(流時) period. - If
datecontains a time inYYYY-M-D HHformat or is aDateinstance, andtimeIndexis omitted, the hour indateis converted to a traditional time slot for thehourly(流時) period. - If supplied,
timeIndextakes precedence over the time derived from the date.
- If
Definition
tstype horoscope = (date?: string | Date, timeIndex?: number) => FunctionalHoroscope;Parameters
Parameter Type Required? Default value Description date string|Datefalsenew Date()Gregorian date【YYYY-M-D】 timeIndex numberfalse0Time-slot index [0–12] Return value
Note
In
v1.3.4, the return type changed fromHoroscopetoFunctionalHoroscope. Existing usage remains backward compatible.Example
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); const horoscope = astrolabe.horoscope();
decadalList() ^2.6.0
Purpose
Returns decadal periods(大限) in order of onset. Array index
0is the first period. Each entry contains the corresponding palace, starting and ending nominal ages and years, stem and branch, four transformations(四化), transit stars(流曜), and the period’s twelve palaces.Definition
tstype decadalList = () => DecadalHoroscope[];Return value
Example
tsconst decadals = astrolabe.decadalList(); const firstDecadal = decadals[0];
yearlyList() ^2.6.0
Purpose
Returns the annual periods(流年) within a decadal period(大限), selected by its index or natal-palace name. Each entry includes nominal age, year, annual stem and branch, four transformations(四化), transit stars(流曜), and the twelve annual palaces.
Definition
tstype yearlyList = ( indexOrName: number | PalaceName ) => YearlyHoroscope[];Parameters
Parameter Type Required? Default value Description indexOrName number|PalaceNametrue- Decadal-period index ( 0is the first period), or a natal-palace nameReturn value
Example
tsconst firstDecadalYearlies = astrolabe.yearlyList(0); const soulPalaceYearlies = astrolabe.yearlyList("命宫");
monthlyList() ^2.6.0
Purpose
Returns monthly periods(流月) for the specified year. Each entry contains nominal age, year, month, monthly stem and branch, four transformations(四化), transit stars(流曜), and the twelve monthly palaces.
Leap-month rules: a year without a leap month returns 12 entries. With a leap month,
fixLeap=falsereturns 13 entries;fixLeap=truesplits the leap month into days 1–15 and days 16 through month-end, returning 14 entries.Definition
tstype monthlyList = ( year: number, fixLeap?: boolean ) => MonthlyHoroscope[];Parameters
Parameter Type Required? Default value Description year numbertrue- Annual-period year; use the yearlyList()return item’syearfield directly.fixLeap booleanfalsetrueWhether to calculate the first and second halves of a leap month separately Return value
Example
tsconst year = astrolabe.yearlyList(0)[0].year; const adjusted = astrolabe.monthlyList(year); const unadjusted = astrolabe.monthlyList(year, false);
star() ^1.2.0
Purpose
Retrieves a star’s object instance by name.
Definition
tstype star = (starName: StarName) => IFunctionalStar;Parameters
Parameter Type Required? Default value Description starName StarNametrue- Star name Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 获取 `紫微星` 所在宫位 const star = astrolabe.star("紫微");
palace() ^1.0.0
Purpose
Retrieves the requested
palace(宮位) from the chart.Definition
tstype palace = ( indexOrName: number | PalaceName ) => IFunctionalPalace | undefined;Parameters
Parameter Type Required? Default value Description indexOrName number|PalaceNametrue- Palace index or name Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 获取 `寅宫` const palace = astrolabe.palace(0); // 获取 `命宫` const soulPalace = astrolabe.palace("命宫");
surroundedPalaces() ^1.1.0
Purpose
Retrieves
trine and opposite palaces(三方四正): the suppliedtarget palace, itsopposite palace(對宮), and its relativewealth position(財帛位) andcareer position(官祿位), four palaces in total.palaceandpositionare distinct concepts; see palaces for their meanings and the surrounding-palace relationships.Definition
tstype surroundedPalaces = ( indexOrName: number | PalaceName ) => IFunctionalSurpalaces;Parameters
Parameter Type Required? Default value Description indexOrName number|PalaceNametrue- Palace index or name Return value
Example
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 获取 `寅宫` 三方四正 const surroundedPalaces = astrolabe.surroundedPalaces(0); // 获取 `命宫` 三方四正 const surroundedPalacesOfSoul = astrolabe.surroundedPalaces("命宫");
isSurrounded() ^1.0.0 deprecated
Note
This method was deprecated in
v1.2.0. Use the have() method of FunctionalSurpalaces instead.Purpose
Checks the palace and its
trine and opposite palaces(三方四正) for the requestedstars(星曜). It returnstrueonly when all requested stars are present.Definition
tstype isSurrounded = ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean;Parameters
Parameter Type Required? Default value Description indexOrName number|PalaceNametrue- Palace index or name stars StarName[]true- Array of star names Return value
booleanExample
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 判断 `寅宫` 三方四正是否含有 `天府` 星、`红鸾` 星和 `禄存` 星 const palace = astrolabe.isSurrounded(0, ["天府", "红鸾", "禄存"]); // 判断 `命宫` 三方四正是否含有 `天府` 星、`红鸾` 星和 `禄存` 星 const soulPalace = astrolabe.isSurrounded("命宫", ["天府", "红鸾", "禄存"]);
isSurroundedOneOf() ^1.1.0 deprecated
Note
This method was deprecated in
v1.2.0. Use the haveOneOf() method of FunctionalSurpalaces instead.Purpose
Checks whether the palace and its
trine and opposite palaces(三方四正) containany oneof the supplied stars. At leastoneis enough to returntrue.Definition
tstype isSurroundedOneOf = ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean;Parameters
Parameter Type Required? Default value Description indexOrName number|PalaceNametrue- Palace index or name stars StarName[]true- Array of star names Return value
booleanExample
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 判断 `寅宫` 三方四正是否含有 `天府` 星、`红鸾` 星和 `禄存` 星中的一颗 const palace = astrolabe.isSurroundedOneOf(0, ["天府", "红鸾", "禄存"]); // 判断 `命宫` 三方四正是否含有 `天府` 星、`红鸾` 星和 `禄存` 星中的一颗 const soulPalace = astrolabe.isSurroundedOneOf("命宫", ["天府", "红鸾", "禄存"]);
notSurrounded() ^1.1.0 deprecated
Note
This method was deprecated in
v1.2.0. Use the notHave() method of FunctionalSurpalaces instead.Purpose
Checks whether the palace and its
trine and opposite palaces(三方四正)do not containany requested stars. All requested stars must beabsentfor it to returntrue.Definition
tstype notSurrounded = ( indexOrName: number | PalaceName, stars: StarName[] ) => boolean;Parameters
Parameter Type Required? Default value Description indexOrName number|PalaceNametrue- Palace index or name stars StarName[]true- Array of star names Return value
booleanExample
tsimport { astro } from "iztro"; const astrolabe = astro.astrolabeBySolarDate("2000-8-16", 2, "女", true, "zh-CN"); // 判断 `寅宫` 三方四正是否不含有 `天府` 星、`红鸾` 星和 `禄存` 星 const palace = astrolabe.notSurrounded(0, ["天府", "红鸾", "禄存"]); // 判断 `命宫` 三方四正是否不含有 `天府` 星、`红鸾` 星和 `禄存` 星 const soulPalace = astrolabe.notSurrounded("命宫", ["天府", "红鸾", "禄存"]);