NVD3Chart

class nvd3.NVD3Chart.NVD3Chart(**kwargs)

NVD3Chart Base class

Attributes:

  • axislist - All X, Y axis list
  • charttooltip_dateformat - date format for tooltip if x-axis is in date format
  • charttooltip - Custom tooltip string
  • color_category - Defien color category (eg. category10, category20, category20c)
  • color_list - used by pieChart (eg. [‘red’, ‘blue’, ‘orange’])
  • container - Place for graph
  • containerheader - Header for javascript code
  • count - chart count
  • custom_tooltip_flag - False / True
  • date_flag - x-axis contain date format or not
  • dateformat - see https://github.com/mbostock/d3/wiki/Time-Formatting
  • extras - extra modifiers. Use this to modify different attributes of the chart.
  • header_css - False / True
  • header_js - Custom tooltip string
  • height - Set graph height
  • htmlcontent - Contain the htmloutput
  • htmlheader - Contain the html header
  • jschart - Javascript code as string
  • margin_bottom - set the bottom margin
  • margin_left - set the left margin
  • margin_right - set the right margin
  • margin_top - set the top margin
  • model - set the model (ex. pieChart, LineWithFocusChart, MultiBarChart)
  • resize - False / True
  • series - Series are list of data that will be plotted
  • stacked - False / True
  • style - Special style
  • template_page_nvd3 - template variable
  • use_interactive_guideline - False / True
  • width - Set graph width
  • x_axis_date - False / True
  • show_legend - False / True
  • show_labels - False / True
  • assets_directory directory holding the assets (./bower_components/)
  • x_custom_format - False / True - Used with x_axis_format
  • y_custom_format - False / True- Used with y_axis_format
add_chart_extras(extras)

Use this method to add extra d3 properties to your chart. For example, you want to change the text color of the graph:

chart = pieChart(name='pieChart', color_category='category20c', height=400, width=400)

xdata = ["Orange", "Banana", "Pear", "Kiwi", "Apple", "Strawberry", "Pineapple"]
ydata = [3, 4, 0, 1, 5, 7, 3]

extra_serie = {"tooltip": {"y_start": "", "y_end": " cal"}}
chart.add_serie(y=ydata, x=xdata, extra=extra_serie)

The above code will create graph with a black text, the following will change it:

text_white="d3.selectAll('#pieChart text').style('fill', 'white');"
chart.add_chart_extras(text_white)

The above extras will be appended to the java script generated.

Alternatively, you can use the following initialization:

chart = pieChart(name='pieChart',
                 color_category='category20c',
                 height=400, width=400,
                 extras=text_white)
add_serie(y, x, name=None, extra={}, **kwargs)

add serie - Series are list of data that will be plotted y {1, 2, 3, 4, 5} / x {1, 2, 3, 4, 5}

Attributes:

  • name - set Serie name
  • x - x-axis data
  • y - y-axis data

kwargs:

  • shape - for scatterChart, you can set different shapes (circle, triangle etc...)
  • size - for scatterChart, you can set size of different shapes
  • type - for multiChart, type should be bar
  • bar - to display bars in Chart
  • color_list - define list of colors which will be used by pieChart
  • color - set axis color
  • disabled -

extra:

  • tooltip - set tooltip flag
  • date_format - set date_format for tooltip if x-axis is in date format
buildcontainer()

generate HTML div

buildcontent()

Build HTML content only, no header or body tags. To be useful this will usually require the attribute juqery_on_ready to be set which will wrap the js in $(function(){<regular_js>};)

buildhtml()

Build the HTML page Create the htmlheader with css / js Create html page Add Js code for nvd3

buildhtmlheader()

generate HTML header content

buildjschart()

generate javascript code for the chart

create_x_axis(name, label=None, format=None, date=False, custom_format=False)

Create X-axis

create_y_axis(name, label=None, format=None, custom_format=False)

Create Y-axis

set_containerheader(containerheader)

Set containerheader

set_custom_tooltip_flag(custom_tooltip_flag)

Set custom_tooltip_flag & date_flag

set_date_flag(date_flag=False)

Set date flag

set_graph_height(height)

Set Graph height

set_graph_width(width)

Set Graph width

slugify_name(name)

Slufigy name with underscore