Skip to content

Commit

Permalink
Add support for material charts (Bar and Line)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn committed Apr 13, 2017
1 parent 2971c0e commit 1fb673c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 46 deletions.
3 changes: 3 additions & 0 deletions classes/headers/ChartHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class ChartHeader extends HeaderBase {
'WordTree',
'Gauge',
'Gantt',
// Material charts
'Bar',
'Line',
),
'default'=>'LineChart'
),
Expand Down
2 changes: 1 addition & 1 deletion templates/default/html/chart_page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script src="{{base}}/public/js/jquery-2.0.3.min.js"></script>
<script>
google.charts.load("current", {packages:["corechart","geochart","annotatedtimeline","gauge","gantt"]});
google.charts.load('current', {packages:["corechart","geochart","annotatedtimeline","gauge","gantt","bar","line"]});
</script>
<script src="{{ base }}/public/js/timeline.js"></script>
<link rel="stylesheet" type="text/css" href="{{ base }}/public/css/timeline.css">
Expand Down
50 changes: 5 additions & 45 deletions templates/default/html/chart_report.twig
Original file line number Diff line number Diff line change
Expand Up @@ -82,57 +82,17 @@
{% if chart.type == "Timeline" %}
var chart_{{chart.num}} = new links.Timeline(document.getElementById('chart_div_{{chart.num}}'));
{% elseif chart.type == "Bar" or chart.type == "Line" %}
var chart_{{chart.num}} = new google.charts.{{chart.type}}(document.getElementById('chart_div_{{chart.num}}'));
options_{{chart.num}} = google.charts.{{chart.type}}.convertOptions(options_{{chart.num}});
{% else %}
var chart_{{chart.num}} = new google.visualization.{{chart.type}}(document.getElementById('chart_div_{{chart.num}}'));
var chart_{{chart.num}} = new google.visualization.{{chart.type}}(document.getElementById('chart_div_{{chart.num}}'));
{% endif %}
google.visualization.events.addListener(chart_{{chart.num}}, 'select', function () {
select2hide(chart_{{chart.num}}, data_{{chart.num}}, options_{{chart.num}}, columns_{{chart.num}}, series_{{chart.num}});
});
{% if chart.type == "BarChart" %}
google.visualization.events.addListener(chart_{{chart.num}}, 'ready', function () {
$('#chart_div_{{chart.num}}').find('text[text-anchor=end]').each(function () {
$(this).attr('x', 25);
$(this).attr('text-anchor', 'front');
});
});
{% endif %}
chart_{{chart.num}}.draw(data_{{chart.num}}, options_{{chart.num}});
chart_{{chart.num}}.draw(data_{{chart.num}}, options_{{chart.num}});
{% endfor %}
}
function select2hide (chart, data, options, columns, series) {
var sel = chart.getSelection();
// if selection length is 0, we deselected an element
if (sel.length > 0) {
// if row is undefined, we clicked on the legend
if (sel[0].row == null) {
var col = sel[0].column;
if (columns[col] == col) {
// hide the data series
columns[col] = {
label: data.getColumnLabel(col),
type: data.getColumnType(col),
calc: function () {
return null;
}
};
// grey out the legend entry
series[col - 1].color = '#CCCCCC';
} else {
// show the data series
columns[col] = col;
series[col - 1].color = null;
}
var view = new google.visualization.DataView(data);
view.setColumns(columns);
chart.draw(view, options);
}
}
}
google.charts.setOnLoadCallback(drawCharts);
</script>
{% endblock %}

0 comments on commit 1fb673c

Please sign in to comment.