<% data = [{ name: 'Installation', data: [1475,200,3000,654,656] }, { name: 'Manufacturing', data: [4434,524,2320,440,500] }, { name: 'Sales & Distribution', data: [3387,743,1344,434,440,] }, { name: 'Project Development', data: [3227,878,999,780,1000] }, { name: 'Other', data: [1111,677,3245,500,200] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-default", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], subtitle: 'Source: thesolarfoundation.com', title: 'Solar Employment Growth by Sector, 2010-2016', }) %>
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-test-2", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Legend', legend: true, }) %>
align
Type: String | Values: left | center | right (defaults to center)
verticalAlign
Type: String | Values: top | middle | bottom (defaults middle)
layout
Type: String | Values: horizontal | vertical | proximate (defaults to horizontal)
x
Type: Number (defaults to 0)
y
Type: Number (defaults to 0)
layout
determines the position of the legend items
layout: proximate
will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x
offsets the legend relative to its horizontal alignmnet. Negative x moves it to the left, positive x moves it to the right
y
offsets the legend relative to its vertical alignmnet. Negative y moves it up, positive y moves it down.
<% data = [{ name: 'Installation', data: [1475] }, { name: 'Manufacturing', data: [4434] }, { name: 'Sales & Distribution', data: [3387] }, { name: 'Project Development', data: [3227] }, { name: 'Other', data: [1111] }] %> <%= pb_rails("title", props: {size: 4, text: "align | vertical_align", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id:"legend-position-bar", y_axis_min: 0, x_axis_categories:['Jan'], title: 'Alignment of Legend', legend: true, align: 'right', vertical_align: 'top', padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id:"legend-position-bar-1", y_axis_min: 0, x_axis_categories:['Jan'], title: 'Layout of Legend', legend: true, layout: 'vertical', padding_top: "sm", padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id:"legend-position-bar-2", y_axis_min: 0, x_axis_categories:['Jan'], title: 'Offset of Legend', legend: true, layout: "vertical", x: 100, y: 10, padding_top: "sm", }) %>
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-test-3", y_axis_min: 0, x_axis_categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Legend Non Clickable', legend: true, toggle_legend_click: false, }) %>
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-fixed-height", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Fixed Height (300px)', height: '300' }) %> <br /><br /> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-percentage-height", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Percentage Height (50%)', height: '50%' }) %>
A spline can be added by including a separate chart data with the type: 'spline'
attribute.
A color can also be specified for the spline.
<% data = [{ name: 'Number of Installations', data: [1475,200,3000,654,656] }, { type: 'spline', name: 'Trend Line', data: [1975, 600, 2500, 924, 500], color: '#F9BB00', }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-spline", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], subtitle: 'Source: thesolarfoundation.com', title: 'Bar Graph with Spline', legend: true, }) %>
Custom data colors
allow for color customization to match the needs of business requirements.
Pass the prop colors and use desired values data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8
in an array. Hex colors are also available eg: #CA0095
<% data = [{ name: 'Installation', data: [1475,200,3000,654,656] }, { name: 'Manufacturing', data: [4434,524,2320,440,500] }, { name: 'Sales & Distribution', data: [3387,743,1344,434,440,] }, { name: 'Project Development', data: [3227,878,999,780,1000] }, { name: 'Other', data: [1111,677,3245,500,200] }] %> <%= pb_rails("bar_graph", props: { axis_title: 'Number of Employees', chart_data: data, id: "bar-colors", y_axis_min: 0, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Bar Graph with Custom Data Colors', colors: ['data-4', 'data-5', 'data-6', 'data-7', 'data-8'] }) %>
<% data_51 = [{ name: 'Waiting for Calls', value: 41, }, { name: 'On Call', value: 49, }, { name: 'After call', value: 10, } ] %> <br><br> <%= pb_rails("circle_chart", props: { chart_data: data_51, id: "with-a-block-2", rounded: true, }) do %> <%= pb_rails('title', props: {text: "83", size: 1, tag: 'div'}) %> <% end %>
Custom data colors allow for color customization to match the needs of business requirements.
Pass the prop colors
and use desired values data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8
in an array. Hex colors are also available eg: #CA0095
<% data = [{ name: 'Facebook', value: 2498, }, { name: 'YouTube', value: 2000, }, { name: 'WhatsApp', value: 2000, }, { name: 'Facebook Messenger', value: 1300, }, { name: 'WeChat', value: 1165, }, { name: 'Instagram', value: 1000, }, { name: 'Tik Tok', value: 800, }, ] %> <%= pb_rails("circle_chart", props: { style: "pie", chart_data: data, id: "with-labels-example", data_labels: true }) %>
align
Type: String | Values: left | center | right (defaults to center)
verticalAlign
Type: String | Values: top | middle | bottom (defaults middle)
layout
Type: String | Values: horizontal | vertical | proximate (defaults to horizontal)
x
Type: Number (defaults to 0)
y
Type: Number (defaults to 0)
layout
determines the position of the legend items
layout: proximate
will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x
offsets the legend relative to its horizontal alignmnet. Negative x moves it to the left, positive x moves it to the right
y
offsets the legend relative to its vertical alignmnet. Negative y moves it up, positive y moves it down.
<% data = [{ name: 'Waiting for Calls', value: 41, }, { name: 'On Call', value: 49, }, { name: 'After call', value: 10, } ] %> <% data_1 = [{ name: 'Bugs', value: 8, }, { name: 'Chores', value: 1, }, { name: 'Stories', value: 12, } ] %> <% data_2 = [{ name: 'Queued', value: 7, }, { name: 'In Progress', value: 6, }, { name: 'Validation', value: 3, }, { name: 'Done', value: 6, }, ] %> <%= pb_rails("title", props: {size: 4, text: "align | vertical_align", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("circle_chart", props: { style: "pie", chart_data: data, legend: true, id: "legend-position-circle", title: 'Alignment of Legend', align: 'right', vertical_align: 'top', padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("circle_chart", props: { style: "pie", chart_data: data_1, legend: true, id: "legend-position-circle-1", title: 'Layout of Legend', layout: 'vertical', padding_top: "sm", padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("circle_chart", props: { style: "pie", chart_data: data_2, legend: true, title: 'Offset of Legend', id: "legend-position-circle-2", x: 100, y: 10, padding_top: "sm", }) %>
<% data_5 = [{ name: 'Facebook', value: 2498, }, { name: 'YouTube', value: 2000, }, { name: 'WhatsApp', value: 2000, }, { name: 'Facebook Messenger', value: 1300, }, { name: 'WeChat', value: 1165, }, { name: 'Instagram', value: 1000, }, { name: 'Tik Tok', value: 800, }, ] %> <%= pb_rails("circle_chart", props: { style: "pie", title: "Active Users on Social Media", chart_data: data_5, id: "with-caption-example", }) %>
<% data_1 = [{ name: 'Bugs', value: 8, }, { name: 'Chores', value: 1, }, { name: 'Stories', value: 12, } ] %> <% data_2 = [{ name: 'Queued', value: 7, }, { name: 'In Progress', value: 6, }, { name: 'Validation', value: 3, }, { name: 'Done', value: 6, }, ] %> <% data_3 = [{ name: '1 Point Tickets', value: 2, }, { name: '3 Point Tickets', value: 5, }, { name: '5 Point Tickets', value: 6, }, { name: '8 Point Tickets', value: 3, }, { name: '13 Point Tickets', value: 1, }, ] %> <% data_4 = [{ name: 'Facebook', value: 2498, }, { name: 'YouTube', value: 2000, }, { name: 'WhatsApp', value: 2000, }, { name: 'Facebook Messenger', value: 1300, }, { name: 'WeChat', value: 1165, }, { name: 'Instagram', value: 1000, }, { name: 'Tik Tok', value: 800, }, ] %> <%= pb_rails("circle_chart", props: { chart_data: data_1, id: "size-test-1", min_point_size: 2, max_point_size: 200, inner_size: "sm", z_min: 0, start_angle: 0, header_format: '', }) %> <%= pb_rails("circle_chart", props: { chart_data: data_2, id: "size-test-2", min_point_size: 2, max_point_size: 200, inner_size: "md", z_min: 0, start_angle: 0, header_format: '', }) %> <%= pb_rails("circle_chart", props: { chart_data: data_3, id: "size-test-3", min_point_size: 2, max_point_size: 200, inner_size: "lg", z_min: 0, start_angle: 0, header_format: '', }) %> <%= pb_rails("circle_chart", props: { chart_data: data_4, id: "size-test-4", min_point_size: 2, max_point_size: 200, inner_size: "none", z_min: 0, start_angle: 0, header_format: '', }) %>
A custom tooltip format can be specified. The desired format can be passed as a string
of custom HTML to the tooltipHtml
prop.
{point.name}
and {point.y}
are useful values that can be referenced for each point in the graph.
<% data = [{ name: 'Waiting for Calls', value: 41, }, { name: 'On Call', value: 49, }, { name: 'After call', value: 10, } ] %> <%= pb_rails("circle_chart", props: { chart_data: data, tooltip_html: "<p>Custom tooltip for {point.name} <br/>with value: {point.y}</p>", id: "default-test" }) %>
You can customize the order of the colors you would like to use by using the colors
prop. Only the data and status colors will work for Playbook charts. See the design page for reference.
<% data1 = [ { name: 'Data Used', value: 32, } ]%> <%= pb_rails("gauge", props: { id: "gauge-units1", chart_data: data1, title: "Data Usage", suffix: "GB" }) %> <% data2 = [ { name: 'Sales to Date', value: 65, } ]%> <%= pb_rails("gauge", props: { id: "gauge-units2", chart_data: data2, title: "Sales Goal", prefix: "$", suffix: "k", }) %>
overflow
to hidden on the parent element when nesting gauges inside of a flex items to best respond to shrinking screens. <%= pb_rails("flex", props: {wrap: true, align: "center"}) do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "400px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("gauge", props: { id: "gauge-sizing4", chart_data: [{ name: "Point 1", value: 100 }], }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "300px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("gauge", props: { id: "gauge-sizing3", chart_data: [{ name: "Point 2", value: 75 }], }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "200px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("gauge", props: { id: "gauge-sizing2", chart_data: [{ name: "Point 3", value: 50 }], }) %> <% end %> <%= pb_rails("flex/flex_item", props: {fixed_size: "125px", overflow: "hidden", shrink: true }) do %> <%= pb_rails("gauge", props: { id: "gauge-sizing1", height: '100%', chart_data: [{ name: "Point 4", value: 25 }], }) %> <% end %> <% end %>
<%= pb_rails("gauge", props: { id: "gauge-height-px", chart_data: [{ name: "Pixels", value: 400 }], height: '400', title: "Fixed Height in Pixels", suffix: "px" }) %> <%= pb_rails("gauge", props: { id: "gauge-height-percent", chart_data: [{ name: "Percentage", value: 45 }], height: '45%', title: "Height as Percentage of Width", suffix: "%" }) %>
Custom data colors allow for color customization to match the needs of business requirements.
Pass the prop colors
and use ONE desired value data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8
in an array. Hex colors are also available eg: #CA0095
We are able to wrap our Gauge kits within multiple other Flex and Card components.
<%= pb_rails("flex", props: {wrap: true, padding: "xl", gap: "sm"}) do %> <%= pb_rails("flex/flex_item", props: {flex: 1, grow: true }) do %> <%= pb_rails("card", props: {max_width: "xs", padding: "md", }) do %> <%= pb_rails("title", props: {padding_bottom: "sm", size: 4, text: "Abandoned Calls" })%> <%= pb_rails("flex", props: {align: "stretch"}) do %> <%= pb_rails("flex", props: {margin_right: "sm", orientation: "column"}) do %> <%= pb_rails("body", props: {color: "light", padding_bottom: "sm",text: "Total Abandoned"}) %> <%= pb_rails("flex", props: {align: "baseline", padding_bottom: "sx"}) do %> <%= pb_rails("title", props: {size: 1, text: "39"})%> <%= pb_rails("title", props: {color: "light", size: 3, text: "calls"}) %> <% end %> <%= pb_rails("caption", props: {size: "xs", text: "of 390" }) %> <%end %> <%= pb_rails("section_separator", props: {align_self: "stretch", margin_right: "sm", orientation: "vertical" }) %> <%= pb_rails("flex", props: {orientation: "column", wrap: true}) do %> <%= pb_rails("body", props: {color: "light", text: "% Abandoned"}) %> <%= pb_rails("flex", props: {wrap: true}) do %> <%= pb_rails("flex/flex_item", props: {fixed_size: "150px", overflow: "hidden", shrink: true}) do %> <%= pb_rails("gauge", props: { chart_data: [{ name: "Name", value: 10 }], disable_animation: true, height: '150', id: "gauge-complex", suffix: "%" }) %> <% end %> <% end %> <% end %> <%end %> <% end %> <% end %> <% end %>
By default legend kit uses data_1
color.
Pass the color prop and use any desired value from $data_colors
, $status_colors
, $product_colors
and $category_colors
list.
<%= pb_rails("legend", props: { color: "data_8", text: "Data 8" }) %> <%= pb_rails("legend", props: { color: "warning", text: "Warning" }) %> <%= pb_rails("legend", props: { color: "product_6_highlight", text: "Product 6 (highlight)" }) %> <%= pb_rails("legend", props: { color: "category_7", text: "Category 7" }) %>
The color prop also allows for use of custom colors passed in as HEX codes.
<% data = [{ name: 'Installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] }, { name: 'Manufacturing', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434] }, { name: 'Sales & Distribution', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387] }, { name: 'Project Development', data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227] }, { name: 'Other', data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111] }] %> <%= pb_rails("line_graph", props: { id: "line-default", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Solar Employment Growth by Sector, 2010-2016', subtitle: 'Source: thesolarfoundation.com', axis_title: 'Number of Employees' }) %>
<% data = [{ name: 'Number of Installations', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] }] %> <%= pb_rails("line_graph", props: { id: "line-test-2", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'], title: 'Line Graph with Legend', axis_title: 'Number of Employees', legend: true }) %>
align
Type: String | Values: left | center | right (defaults to center)
verticalAlign
Type: String | Values: top | middle | bottom (defaults middle)
layout
Type: String | Values: horizontal | vertical | proximate (defaults to horizontal)
x
Type: Number (defaults to 0)
y
Type: Number (defaults to 0)
layout
determines the position of the legend items
layout: proximate
will place the legend items as close as possible to the graphs they're representing. It will also determine whether to place the legend above/below or on the side of the plot area, if the legend is in a corner.
x
offsets the legend relative to its horizontal alignmnet. Negative x moves it to the left, positive x moves it to the right
y
offsets the legend relative to its vertical alignmnet. Negative y moves it up, positive y moves it down.
<% data = [{ name: 'Installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] }, { name: 'Manufacturing', data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434] }, { name: 'Sales & Distribution', data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387] }, { name: 'Project Development', data: [nil, nil, 7988, 12169, 15112, 22452, 34400, 34227] }, { name: 'Other', data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111] }] %> <%= pb_rails("title", props: {size: 4, text: "align | vertical_align", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("line_graph", props: { id: "legend-position-line", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'], title: 'Alignment of Legend', axis_title: 'Number of Employees', legend: true, align: 'right', vertical_align: 'top', padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "layout", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("line_graph", props: { id: "legend-position-line-1", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'], title: 'Layout of Legend', axis_title: 'Number of Employees', legend: true, layout: 'vertical', padding_top: "sm", padding_bottom: "sm", }) %> <%= pb_rails("title", props: {size: 4, text: "x | y", padding_top: "sm", padding_bottom: "sm"})%> <%= pb_rails("line_graph", props: { id: "legend-position-line-2", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'], title: 'Offset of Legend', axis_title: 'Number of Employees', legend: true, layout: "vertical", x: 100, y: 10, padding_top: "sm", }) %>
<% data = [{ name: 'Number of Installations', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] }] %> <%= pb_rails("line_graph", props: { id: "line-test-3", gradient: false, chart_data: data, x_axis_categories: ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug'], title: 'Line Graph with Legend Non Clickable', axis_title: 'Number of Employees', legend: true, toggle_legend_click: false, }) %>
<% data = [{ name: 'Number of Installations', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] }] %> <%= pb_rails("line_graph", props: { id: "line-fixed-height", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Fixed Height (300px)', axis_title: 'Number of Employees', height: '300' }) %> <br /><br /> <%= pb_rails("line_graph", props: { id: "line-precentage-height", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Percentage Height (50%)', axis_title: 'Number of Employees', height: '50%' }) %>
Custom data colors allow for color customization to match the needs of business requirements.
Pass the prop colors
and use desired values data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8
in an array. Hex colors are also available eg: #CA0095
<% data = [{ name: 'Installation', data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175] }, { name: 'Manufacturing', data: [24916, 28064, 29742, 40851, 50590, 65282, 70121, 85434] }, { name: 'Sales & Distribution', data: [11744, 17722, 16005, 19771, 25185, 28377, 36147, 43387] }, { name: 'Project Development', data: [5332, 6344, 7988, 12169, 15112, 14452, 22400, 30227] }, { name: 'Other', data: [nil, nil, nil, 3112, 4989, 5816, 15274, 18111] }] %> <%= pb_rails("line_graph", props: { id: "line-colors", gradient: false, chart_data: data, x_axis_categories:['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], title: 'Line Graph with Custom Data Colors', axis_title: 'Number of Employees', colors: ['data-4', 'data-5', 'data-6', 'data-7', 'data-8'] }) %>
Points are automatically arranged by their value
size.
By default, point colors are assigned sequentially from the global data
colors. Note that data points without a value (such as parent nodes) will still take on the next available color.
<% data = [ { name: "Pepperoni", parent: "Toppings", value: 600, }, { name: "Cheese", parent: "Toppings", value: 510, }, { name: "Mushroom", parent: "Toppings", value: 330, },{ name: "Onions", parent: "Toppings", value: 250, }, { name: "Olives", parent: "Toppings", value: 204, }, { name: "Pineapple", parent: "Toppings", value: 90, }, { name: "Pizza Toppings", id: "Toppings", }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, id: "treemap-default", title: "Favored Pizza Toppings", }) %>
Data can be grouped into distinct segments by specifying the relationship in the chartData
. For a point to be a parent, it needs an id
of type string
included in its object. Any other data points may then reference that id
as their parent
value to establish the tree structure.
Parents can also be passed a custom color to be applied to all of its child points.
<% data = [ { name: 'Meat', id: 'Meat', color: "#0056CF", }, { name: 'Pepperoni', parent: 'Meat', value: 250, }, { name: 'Meatball', parent: 'Meat', value: 400, }, { name: "Anchovy", parent: 'Meat', value: 40, }, { name: 'Vegetarian', id: 'Vegetarian', color: "#F9BB00", }, { name: 'Onions', parent: 'Vegetarian', value: 300, }, { name: 'Pineapple', parent: 'Vegetarian', value: 90, }, { name: "Peppers", parent: 'Vegetarian', value: 80, }, { name: "Specialty", id: "Specialty", color: "#9E64E9", },{ name: "Buffalo Chicken", parent: "Specialty", value: 400, }, { name: "Supreme", parent: "Specialty", value: 150, } ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, grouped: true, id: "treemap-grouped", title: "Grouped Toppings", }) %>
Adding the drillable
prop allows the tree to be traversed up and down by clicking into each box. Relationships are established through the chartData
, detailed in the Grouped Data section above.
<% data = [ { name: "Evergreen", id: "Evergreen", color: "#0056CF", }, { name: "Pine", id: "Pine", parent: "Evergreen", value: 300, color: "#477BC4", }, { name: "Ponderosa Pine", parent: "Pine", value: 50, }, { name: "Scots Pine", parent: "Pine", value: 150, }, { name: "White Pine", parent: "Pine", value: 100, }, { name: "Douglas Fir", parent: "Evergreen", value: 150, }, { name: "Juniper", parent: "Evergreen", value: 80, }, { name: "Hemlock", parent: "Evergreen", value: 30, }, { name: "Deciduous", id: "Deciduous", color: "#F9BB00", }, { name: "Oak", parent: "Deciduous", value: 80, }, { name: "Maple", id: "Maple", parent: "Deciduous", value: 180, color: "#F7CE52", }, { name: "Red Maple", parent: "Maple", value: 80, }, { name: "Sugar Maple", parent: "Maple", value: 100, }, { name: "Beech", parent: "Deciduous", value: 50, }, { name: "Willow", parent: "Deciduous", value: 100, }, { name: "Juniper", parent: "Deciduous", value: 90, }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, drillable: true, grouped: true, id: "treemap-drillable", title: "Drillable Grouped Tree Species", }) %>
Custom data colors allow for color customization to match the needs of business requirements.
Pass the prop colors
and use desired values data-1 | data-2 | data-3 | data-4 | data-5 | data-6 | data-7 | data-8
in an array. Hex colors are also available eg: #CA0095
<% data = [ { name: "Pepperoni", parent: "Toppings", value: 600, }, { name: "Cheese", parent: "Toppings", value: 510, }, { name: "Mushroom", parent: "Toppings", value: 330, },{ name: "Onions", parent: "Toppings", value: 250, }, { name: "Olives", parent: "Toppings", value: 204, }, { name: "Pineapple", parent: "Toppings", value: 90, }, { name: "Pizza Toppings", id: "Toppings", }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, colors: ["data-4", "data-7", "#8E6E53", "#124732"], id: "treemap-colors", title: "Favored Pizza Toppings", }) %>
A custom tooltip format can be specified. The desired format can be passed as a string
of custom HTML to the tooltipHtml
prop.
{point.name}
and {point.value}
are useful values that can be referenced for each point in the graph.
<% data = [ { name: "Pepperoni", parent: "Toppings", value: 600, }, { name: "Cheese", parent: "Toppings", value: 510, }, { name: "Mushroom", parent: "Toppings", value: 330, },{ name: "Onions", parent: "Toppings", value: 250, }, { name: "Olives", parent: "Toppings", value: 204, }, { name: "Pineapple", parent: "Toppings", value: 90, }, { name: "Pizza Toppings", id: "Toppings", }, ] %> <%= pb_rails("treemap_chart", props: { chart_data: data, id: "treemap-tooltip", title: "Favored Pizza Toppings", tooltip_html: "<p>Custom tooltip for {point.name} <br/>with value: {point.value}</p>", }) %>