Skip to content

document TickFormat #288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/01_0_axis-styling.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@ plot2
plot2 |> GenericChart.toChartHTML
(***include-it-raw***)

(**
### Formatting the tick label

You can use `TickFormat` to format the tick label. The formatting rule uses the d3 formatting mini-languages which are very similar to those in Python. See [here](https://github.com/d3/d3-3.x-api-reference/blob/master/Formatting.md#d3_format) for numbers and [here](https://github.com/d3/d3-time-format#locale_format) for dates. Plotly adds two items to d3's date formatter: "%h" for half of the year as a decimal number as well as "%{n}f" for fractional seconds with n digits. For example, "2016-10-13 09:15:23.456" with TickFormat "%H~%M~%S.%2f" would display "09~15~23.46".

This example styles the x-axis tick labels as dollars and the y-axis tick label as percentages with one decimal place.
*)

let dollarAxis = LinearAxis.init(TickFormat="$")
let percentAxis = LinearAxis.init(TickFormat=".1%")

let plot3 =
Chart.Point(x,y)
|> Chart.withXAxis dollarAxis
|> Chart.withYAxis percentAxis

(*** condition: ipynb ***)
#if IPYNB
plot3
#endif // IPYNB

(***hide***)
plot3 |> GenericChart.toChartHTML
(***include-it-raw***)

(**
## Multiple axes
Expand Down