collab/mermaid/docs/syntax/xyChart.mdblame
View source
6dd74de1> **Warning**
6dd74de2>
6dd74de3> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
6dd74de4>
6dd74de5> ## Please edit the corresponding file in [/packages/mermaid/src/docs/syntax/xyChart.md](../../packages/mermaid/src/docs/syntax/xyChart.md).
6dd74de6
6dd74de7# XY Chart
6dd74de8
6dd74de9> In the context of mermaid-js, the XY chart is a comprehensive charting module that encompasses various types of charts that utilize both x-axis and y-axis for data representation. Presently, it includes two fundamental chart types: the bar chart and the line chart. These charts are designed to visually display and analyze data that involve two numerical variables.
6dd74de10
6dd74de11> It's important to note that while the current implementation of mermaid-js includes these two chart types, the framework is designed to be dynamic and adaptable. Therefore, it has the capacity for expansion and the inclusion of additional chart types in the future. This means that users can expect an evolving suite of charting options within the XY chart module, catering to various data visualization needs as new chart types are introduced over time.
6dd74de12
6dd74de13## Example
6dd74de14
6dd74de15```mermaid-example
6dd74de16xychart
6dd74de17 title "Sales Revenue"
6dd74de18 x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
6dd74de19 y-axis "Revenue (in $)" 4000 --> 11000
6dd74de20 bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de21 line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de22```
6dd74de23
6dd74de24```mermaid
6dd74de25xychart
6dd74de26 title "Sales Revenue"
6dd74de27 x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
6dd74de28 y-axis "Revenue (in $)" 4000 --> 11000
6dd74de29 bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de30 line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de31```
6dd74de32
6dd74de33## Syntax
6dd74de34
6dd74de35> **Note**
6dd74de36> All text values that contain only one word can be written without `"`. If a text value has many words in it, specifically if it contains spaces, enclose the value in `"`
6dd74de37
6dd74de38### Orientations
6dd74de39
6dd74de40The chart can be drawn horizontal or vertical, default value is vertical.
6dd74de41
6dd74de42```
6dd74de43xychart horizontal
6dd74de44...
6dd74de45```
6dd74de46
6dd74de47### Title
6dd74de48
6dd74de49The title is a short description of the chart and it will always render on top of the chart.
6dd74de50
6dd74de51#### Example
6dd74de52
6dd74de53```
6dd74de54xychart
6dd74de55 title "This is a simple example"
6dd74de56 ...
6dd74de57```
6dd74de58
6dd74de59> **Note**
6dd74de60> If the title is a single word one no need to use `"`, but if it has space `"` is needed
6dd74de61
6dd74de62### x-axis
6dd74de63
6dd74de64The x-axis primarily serves as a categorical value, although it can also function as a numeric range value when needed.
6dd74de65
6dd74de66#### Example
6dd74de67
6dd74de681. `x-axis title min --> max` x-axis will function as numeric with the given range
6dd74de692. `x-axis "title with space" [cat1, "cat2 with space", cat3]` x-axis if categorical, categories are text type
6dd74de70
6dd74de71### y-axis
6dd74de72
6dd74de73The y-axis is employed to represent numerical range values, it cannot have categorical values.
6dd74de74
6dd74de75#### Example
6dd74de76
6dd74de771. `y-axis title min --> max`
6dd74de782. `y-axis title` it will only add the title, the range will be auto generated from data.
6dd74de79
6dd74de80> **Note**
6dd74de81> Both x and y axis are optional if not provided we will try to create the range
6dd74de82
6dd74de83### Line chart
6dd74de84
6dd74de85A line chart offers the capability to graphically depict lines.
6dd74de86
6dd74de87#### Example
6dd74de88
6dd74de891. `line [2.3, 45, .98, -3.4]` it can have all valid numeric values.
6dd74de90
6dd74de91### Bar chart
6dd74de92
6dd74de93A bar chart offers the capability to graphically depict bars.
6dd74de94
6dd74de95#### Example
6dd74de96
6dd74de971. `bar [2.3, 45, .98, -3.4]` it can have all valid numeric values.
6dd74de98
6dd74de99#### Simplest example
6dd74de100
6dd74de101The only two things required are the chart name (`xychart`) and one data set. So you will be able to draw a chart with a simple config like
6dd74de102
6dd74de103```
6dd74de104xychart
6dd74de105 line [+1.3, .6, 2.4, -.34]
6dd74de106```
6dd74de107
6dd74de108## Chart Configurations
6dd74de109
6dd74de110| Parameter | Description | Default value |
6dd74de111| ------------------------ | ------------------------------------------------------------- | :-----------: |
6dd74de112| width | Width of the chart | 700 |
6dd74de113| height | Height of the chart | 500 |
6dd74de114| titlePadding | Top and Bottom padding of the title | 10 |
6dd74de115| titleFontSize | Title font size | 20 |
6dd74de116| showTitle | Title to be shown or not | true |
6dd74de117| xAxis | xAxis configuration | AxisConfig |
6dd74de118| yAxis | yAxis configuration | AxisConfig |
6dd74de119| chartOrientation | 'vertical' or 'horizontal' | 'vertical' |
6dd74de120| plotReservedSpacePercent | Minimum space plots will take inside the chart | 50 |
6dd74de121| showDataLabel | Should show the value corresponding to the bar within the bar | false |
6dd74de122
6dd74de123### AxisConfig
6dd74de124
6dd74de125| Parameter | Description | Default value |
6dd74de126| ------------- | ------------------------------------ | :-----------: |
6dd74de127| showLabel | Show axis labels or tick values | true |
6dd74de128| labelFontSize | Font size of the label to be drawn | 14 |
6dd74de129| labelPadding | Top and Bottom padding of the label | 5 |
6dd74de130| showTitle | Axis title to be shown or not | true |
6dd74de131| titleFontSize | Axis title font size | 16 |
6dd74de132| titlePadding | Top and Bottom padding of Axis title | 5 |
6dd74de133| showTick | Tick to be shown or not | true |
6dd74de134| tickLength | How long the tick will be | 5 |
6dd74de135| tickWidth | How width the tick will be | 2 |
6dd74de136| showAxisLine | Axis line to be shown or not | true |
6dd74de137| axisLineWidth | Thickness of the axis line | 2 |
6dd74de138
6dd74de139## Chart Theme Variables
6dd74de140
6dd74de141Themes for xychart reside inside the `xychart` attribute, allowing customization through the following syntax:
6dd74de142
6dd74de143```yaml
6dd74de144---
6dd74de145config:
6dd74de146 themeVariables:
6dd74de147 xyChart:
6dd74de148 titleColor: '#ff0000'
6dd74de149---
6dd74de150```
6dd74de151
6dd74de152| Parameter | Description |
6dd74de153| ---------------- | --------------------------------------------------------- |
6dd74de154| backgroundColor | Background color of the whole chart |
6dd74de155| titleColor | Color of the Title text |
6dd74de156| xAxisLabelColor | Color of the x-axis labels |
6dd74de157| xAxisTitleColor | Color of the x-axis title |
6dd74de158| xAxisTickColor | Color of the x-axis tick |
6dd74de159| xAxisLineColor | Color of the x-axis line |
6dd74de160| yAxisLabelColor | Color of the y-axis labels |
6dd74de161| yAxisTitleColor | Color of the y-axis title |
6dd74de162| yAxisTickColor | Color of the y-axis tick |
6dd74de163| yAxisLineColor | Color of the y-axis line |
6dd74de164| plotColorPalette | String of colors separated by comma e.g. "#f3456, #43445" |
6dd74de165
6dd74de166### Setting Colors for Lines and Bars
6dd74de167
6dd74de168To set the color for lines and bars, use the `plotColorPalette` parameter. Colors in the palette will correspond sequentially to the elements in your chart (e.g., first bar/line will use the first color specified in the palette).
6dd74de169
6dd74de170```mermaid-example
6dd74de171---
6dd74de172config:
6dd74de173 themeVariables:
6dd74de174 xyChart:
6dd74de175 plotColorPalette: '#000000, #0000FF, #00FF00, #FF0000'
6dd74de176---
6dd74de177xychart
6dd74de178title "Different Colors in xyChart"
6dd74de179x-axis "categoriesX" ["Category 1", "Category 2", "Category 3", "Category 4"]
6dd74de180y-axis "valuesY" 0 --> 50
6dd74de181%% Black line
6dd74de182line [10,20,30,40]
6dd74de183%% Blue bar
6dd74de184bar [20,30,25,35]
6dd74de185%% Green bar
6dd74de186bar [15,25,20,30]
6dd74de187%% Red line
6dd74de188line [5,15,25,35]
6dd74de189```
6dd74de190
6dd74de191```mermaid
6dd74de192---
6dd74de193config:
6dd74de194 themeVariables:
6dd74de195 xyChart:
6dd74de196 plotColorPalette: '#000000, #0000FF, #00FF00, #FF0000'
6dd74de197---
6dd74de198xychart
6dd74de199title "Different Colors in xyChart"
6dd74de200x-axis "categoriesX" ["Category 1", "Category 2", "Category 3", "Category 4"]
6dd74de201y-axis "valuesY" 0 --> 50
6dd74de202%% Black line
6dd74de203line [10,20,30,40]
6dd74de204%% Blue bar
6dd74de205bar [20,30,25,35]
6dd74de206%% Green bar
6dd74de207bar [15,25,20,30]
6dd74de208%% Red line
6dd74de209line [5,15,25,35]
6dd74de210```
6dd74de211
6dd74de212## Example on config and theme
6dd74de213
6dd74de214```mermaid-example
6dd74de215---
6dd74de216config:
6dd74de217 xyChart:
6dd74de218 width: 900
6dd74de219 height: 600
6dd74de220 showDataLabel: true
6dd74de221 themeVariables:
6dd74de222 xyChart:
6dd74de223 titleColor: "#ff0000"
6dd74de224---
6dd74de225xychart
6dd74de226 title "Sales Revenue"
6dd74de227 x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
6dd74de228 y-axis "Revenue (in $)" 4000 --> 11000
6dd74de229 bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de230 line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de231```
6dd74de232
6dd74de233```mermaid
6dd74de234---
6dd74de235config:
6dd74de236 xyChart:
6dd74de237 width: 900
6dd74de238 height: 600
6dd74de239 showDataLabel: true
6dd74de240 themeVariables:
6dd74de241 xyChart:
6dd74de242 titleColor: "#ff0000"
6dd74de243---
6dd74de244xychart
6dd74de245 title "Sales Revenue"
6dd74de246 x-axis [jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]
6dd74de247 y-axis "Revenue (in $)" 4000 --> 11000
6dd74de248 bar [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de249 line [5000, 6000, 7500, 8200, 9500, 10500, 11000, 10200, 9200, 8500, 7000, 6000]
6dd74de250```