X AXIS spacing
Parkes Design - August 9, 2009 - 10:38
| Project: | Chart API |
| Version: | 6.x-1.2 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Hi, awesome module you've developed. I have a quick question I have created a view style google graph and I know that the x axis will show a maximum of 12 items. When I enter the first 2 values the graph scaling is out of wack and it's not until I enter all 12 values that the graph begins to look the way I wanted it to.
Is there away to tell have the x axis spacing set as a default so the graph doesn't scale?
Code is below
Thankyou in advance
<?php if (!empty($title)): ?>
<h3><?php print $title; ?></h3>
<?php endif; ?>
<?php
$chart = array(
'#chart_id' => 'daily_weight',
'#title' => chart_title(t('Weekly Weight Graph'), '666666', 15),
'#type' => CHART_TYPE_LINE,
'#size' => chart_size(450, 200),
'#adjust_resolution' => TRUE,
);
// You need one element here per datapoint (per row) being displayed
$chart['#data']['dailyweight'] = array();
$max = 0;
foreach ( $view->result as $point ) {
// Set up the data
$chart['#data']['dailyweight'][] = $point->node_data_field_data_field_data_value;
// Calculate the maximum value
if ( $max < $point->node_data_field_data_field_data_value ) {
$max = $point->node_data_field_data_field_data_value;
}
// Add the x-axis label for this data point (example uses node title)
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label($point->node_title);
}
// Add a color for each data point
$chart['#data_colors'][] = 'BCCC32';
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] = chart_mixed_axis_range_label(0, $max);
echo chart_render($chart);
?>
#1
Use the Chart size and bar size options - (barwidth + bar space) * number of bars = chartwidth
default for barwidth is 40px, default for barspace is 20px.
$chart['#size'] = chart_size($chartwidth, 200);
$chart['#bar_size'] = chart_bar_size($barwidth, $barspace);
#2
Hi jwinstanley, Thanks for your reply. Will the #bar_size parameter work on a line chart?
Either way I'll give it a go and will let you know. Thanks again for your input.
#3
subscribing