Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 834e512

Browse files
Mahdis-zJoseph Damibanicolaskruchten
committed
texttemplate.js tutorial (#1565)
* texttemplate.js tutorial * textemplate example charts will be inlined once branch is merged * revive old PR * fix ci * fix ci Co-authored-by: Joseph Damiba <[email protected]> Co-authored-by: Nicolas Kruchten <[email protected]>
1 parent b89a3b4 commit 834e512

4 files changed

+88
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Add Text Template in Pie Chart
3+
language: plotly_js
4+
suite: texttemplate
5+
order: 1
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
To show an arbitrary text in your chart you can use [texttemplate](https://plot.ly/python/reference/#pie-texttemplate), which is a template string used for rendering the information, and will override [textinfo](https://plot.ly/python/reference/#treemap-textinfo).
10+
---
11+
var data = [{
12+
type: "pie",
13+
values: [2, 5, 3, 2.5],
14+
labels: ["R", "Python", "Java Script", "Matlab"],
15+
texttemplate: "%{label}: %{value} (%{percent})",
16+
textposition: "inside"
17+
}];
18+
19+
Plotly.newPlot("myDiv", data)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
name: Customize Text Template
3+
language: plotly_js
4+
suite: texttemplate
5+
order: 2
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
The following example uses [textfont](https://plot.ly/python/reference/#scatterternary-textfont) to customize the added text.
10+
---
11+
var data = [{
12+
type: "scatterternary",
13+
a: [3, 2, 5],
14+
b: [2, 5, 2],
15+
c: [5, 2, 2],
16+
mode: "markers+text",
17+
text: ["A", "B", "C"],
18+
texttemplate: "%{text}<br>(%{a:.2f}, %{b:.2f}, %{c:.2f})",
19+
textposition: "bottom center",
20+
textfont:{'family': "Times", 'size': [18, 21, 20], 'color': ["IndianRed", "MediumPurple", "DarkOrange"]}
21+
}];
22+
23+
Plotly.newPlot("myDiv", data)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
---
2+
name: Set Date in Text Template
3+
language: plotly_js
4+
suite: texttemplate
5+
order: 3
6+
sitemap: false
7+
arrangement: horizontal
8+
markdown_content: |
9+
10+
The following example displays how to show date by setting [axis.type](https://plot.ly/javascript/reference/#layout-yaxis-type) in [funnel charts](https://plot.ly/javascript/funnel-charts/).
11+
---
12+
var data = [{
13+
type: 'funnel',
14+
name: 'Montreal',
15+
orientation: "h",
16+
y: ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"],
17+
x: [100, 60, 40, 20],
18+
textposition: "inside",
19+
texttemplate: "%{label}"
20+
},{
21+
type: "funnel",
22+
name: 'Vancouver',
23+
orientation: "h",
24+
y: ["2018-01-01", "2018-07-01", "2019-01-01", "2020-01-01"],
25+
x: [90, 70, 50, 10],
26+
textposition: "inside",
27+
textinfo: "label"}]
28+
29+
var layout = {yaxis: {type: 'date'}}
30+
31+
Plotly.newPlot("myDiv", data, layout)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: Text Template
3+
permalink: javascript/texttemplate/
4+
description: How to use D3.js-based text template in Plotly.js.
5+
layout: base
6+
thumbnail: thumbnail/texttemplate.jpg
7+
language: plotly_js
8+
has_thumbnail: true
9+
display_as: file_settings
10+
page_type: u-guide
11+
order: 25
12+
---
13+
14+
{% assign examples = site.posts | where:"language","plotly_js" | where:"suite","texttemplate" | sort: "order" %}
15+
{% include posts/auto_examples.html examples=examples %}

0 commit comments

Comments
 (0)