Skip to content

Added Support for Stacked Bar Chart and Column Chart for YUI #65

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
34 changes: 33 additions & 1 deletion demo_project/demo/templates/demo/yui.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ <h2>Column Chart</h2>
chart = yui.ColumnChart(data_source, options={'title': "Sales/ Expense"})
</div>

<br />

<h2> Stacked Column Chart</h2>
<div id="column_chart" class="well">
{{ stacked_column_chart.as_html }}
<pre class="code">
data = [
['Year', 'Sales', 'Expenses', 'Items Sold', 'Net Profit'],
['2004', 1000, 400, 100, 600],
['2005', 1170, 460, 120, 310],
['2006', 660, 1120, 50, -460],
['2007', 1030, 540, 100, 200],
]
data_source = SimpleDataSource(data)
chart = yui.StackedColumnChart(data_source, options={'title': "Sales/ Expense"})
</div>
<br />

<h2>Bar Chart</h2>
Expand All @@ -79,11 +95,27 @@ <h2>Bar Chart</h2>
chart = yui.BarChart(data_source, options={'title': "Expense Growth"})
</pre>
</div>
<br />

<h2>Stacked Bar Chart</h2>
<div id="stacked_bar_chart" class="well">
{{ stacked_bar_chart.as_html }}
<pre class="code">
data = [
['Year', 'Sales', 'Expenses', 'Items Sold', 'Net Profit'],
['2004', 1000, 400, 100, 600],
['2005', 1170, 460, 120, 310],
['2006', 660, 1120, 50, -460],
['2007', 1030, 540, 100, 200],
]
data_source = SimpleDataSource(data)
chart = yui.StackedBarChart(data_source, options={'title': "Sales/ Expense"})
</div>
<br />

<h2>Candlestick Chart</h2>
<div id="candlestick_chart" class="well">
{{ candlestick_chart.as_html }}
{{ candlestick_chart.as_html}}
</div>

<h2>Pie Chart</h2>
Expand Down
9 changes: 8 additions & 1 deletion demo_project/demo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,17 @@ def get_context_data(self, **kwargs):
fields=['year', 'sales'])
area_chart = self.renderer.AreaChart(data_source)
area_spline_chart = self.renderer.AreaSplineChart(data_source)
simple_data_source = SimpleDataSource(data=data)
stacked_bar_chart = self.renderer.StackedBarChart(simple_data_source,
options={'title': "Expense Growth"})
stacked_column_chart = self.renderer.StackedColumnChart(simple_data_source,
options={'title': "Sales/ Expense"})
spline_chart = self.renderer.SplineChart(SimpleDataSource(data=data))
context.update({'area_chart': area_chart,
'area_spline_chart': area_spline_chart,
'spline_chart': spline_chart})
'spline_chart': spline_chart,
'stacked_column_chart': stacked_column_chart,
'stacked_bar_chart': stacked_bar_chart})
return context

yui_demo = YUIDemo.as_view(renderer=yui)
Expand Down
12 changes: 12 additions & 0 deletions graphos/renderers/yui.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def get_js_template(self):
def get_chart_type(self):
return "bar"

class StackedBarChart(BaseYuiChart):
def get_js_template(self):
return "graphos/yui/stacked_bar_chart.html"

def get_chart_type(self):
return "bar"

class ColumnChart(BaseYuiChart):
def get_js_template(self):
Expand All @@ -49,6 +55,12 @@ def get_js_template(self):
def get_chart_type(self):
return "column"

class StackedColumnChart(BaseYuiChart):
def get_js_template(self):
return "graphos/yui/stacked_column_chart.html"

def get_chart_type(self):
return "column"

class PieChart(BaseYuiChart):
def get_js_template(self):
Expand Down
18 changes: 18 additions & 0 deletions graphos/templates/graphos/yui/base_stacked.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
// Create a new YUI instance and populate it with the required modules.
YUI().use('charts', function (Y) {
var datasets = {{ chart.get_data_json|safe }};

{% block yui_chart_type %}
// Instantiate and render the chart
var mychart = new Y.Chart({
dataProvider: datasets,
render: "#{{ chart.get_html_id }}",
type: "{{chart.get_chart_type}}",
categoryKey:"{{ chart.get_category_key }}",
styles: {{ chart.get_options_json|safe }},
stacked:true
});
{% endblock %}
});
</script>
1 change: 1 addition & 0 deletions graphos/templates/graphos/yui/stacked_bar_chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "graphos/yui/base_stacked.html" %}
1 change: 1 addition & 0 deletions graphos/templates/graphos/yui/stacked_column_chart.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{% extends "graphos/yui/base_stacked.html" %}