Hi,
I made a scatter plot with 2 series of data, together these should be 5 points in the graph.
Problem is that the values on the X-axis are plotted fine, while on the Y-axis, they are plotted at some points that seem to be scaled down (they should be higher). E.g. the highest point on the Y-axis is 50, but it's plotted around 12.5, ....
Can someone please take a look. I know I'm almost there. ;-)
// set the series
$one = array(0.0,2.0,20.0,100.0,200.0);
$two = array(4.0,5.0,7.0,10.0,50.0);
//Drupal module chart constructor
$chart = array(
'#chart_id' => 'flyscatter',
'#title' => chart_title(t('Meta-analysis'), 'ff0000', 25),
'#type' => CHART_TYPE_SCATTER,
'#size' => chart_size(500, 500),
'#adjust_resolution' => TRUE,
);
$chart['#data']['series1'] = $one;
$chart['#data']['series2'] = $two;
$chart['#data_colors'][] = '000000';
$grid = array(2,2,1,1);
$chart['#grid_lines'] = $grid;
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][0][] = chart_mixed_axis_range_label(0.0, 200.0);
$chart['#mixed_axis_labels'][CHART_AXIS_X_BOTTOM][1][] = chart_mixed_axis_label(t('Series 1'), 50);
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][0][] = chart_mixed_axis_range_label(0.0, 50.0);
$chart['#mixed_axis_labels'][CHART_AXIS_Y_LEFT][1][] = chart_mixed_axis_label(t('Series 2'), 50);
echo chart_render($chart);
//echo theme('chart', array('chart' => $chart));
echo chart_render($chart);
Comments
Comment #1
13rac1 commentedLooks like #1248066: Margin added in _chart_adjust_resolution() breaks y-axis number alignment is also causing a problem on the X-axis.
Ah. I see the problem: The _chart_adjust_resolution() function changes all values in the data based on your max value of 200. $max is a static, and chart max values are stored by $chart_id, not differentiated by array within the data.
I'm not sure of the best method to fix this. I think we normally want a data set to be normalized to the same maximum, but in the case of a non-even axis scatter plot it doesn't work. Perhaps resolution normalization should be different for scatter plots?
The best thing you can do right now is normalize the data yourself to a max of 100 and turn off #adjust_resolution.
Comment #2
13rac1 commentedSince this is a new feature, it has been fixed in 7.x-1.x only. I added #per_series option to #adjust_resolution. OP example converted to D7, and changed to per series data resolution adjustment is:
Original chart PNG and corrected chart PNG images are attached.