Chart with margin set does not properly crop values above or below set range


As per topic title,
It seems that the chart lines extent in the vertical direction (in pixels) beyond the min/max range (set by lv_chart_set_range) by the margin (set by lv_chart_set_margin).
A mouthfull, but I am sure you get the drift :slight_smile:

What MCU/Processor/Board and compiler are you using?

visual_studio_2017_sdl simulator

What do you experience?

As described above

What do you expect?

Informing you and hoping it will be fixed, unless I am not doing something which case I will gladly take any advice.

Code to reproduce

#define CHART_SET_TICKS		1
static void test_chart_create ( lv_obj_t * par )
	lv_coord_t w_par = lv_obj_get_width( par );
	lv_coord_t h_par = lv_obj_get_height( par );

	static lv_style_t style_chart;
	lv_style_copy( &style_chart, &lv_style_pretty );
	style_chart.body.opa = LV_OPA_60;
	style_chart.body.radius = 0;
	style_chart.line.color = LV_COLOR_GRAY;

	lv_obj_t * chart = lv_chart_create( par, NULL );
	lv_obj_set_size( chart, w_par*2/3, h_par*2/3 );
	lv_chart_set_range( chart, 0, 100 );

	lv_chart_set_margin( chart, 40 );
	lv_chart_set_x_tick_length( chart, 5, 2 );
	lv_chart_set_x_tick_texts( chart,
	lv_chart_set_y_tick_length( chart, 5, 2 );
	lv_chart_set_y_tick_texts( chart,

	lv_chart_set_type( chart, LV_CHART_TYPE_POINT | LV_CHART_TYPE_LINE );
	lv_chart_set_style( chart, LV_CHART_STYLE_MAIN, &style_chart );
	lv_chart_set_series_opa( chart, LV_OPA_70 );

	lv_chart_set_point_count( chart, 20 );

	lv_chart_series_t * ser1, *ser2;
	ser1 = lv_chart_add_series( chart, LV_COLOR_RED );
	ser2 = lv_chart_add_series( chart, LV_COLOR_GREEN );

	int i;
	for( i = 0; i < 20; ++i )
		ser1->points[i] = -20 + i*5;
		ser2->points[i] = -20 + i*10;

	lv_chart_refresh( chart );
	lv_obj_align( chart, NULL, LV_ALIGN_CENTER, 0, 0 );


With Margin,

#define CHART_SET_MARGIN    1
#define CHART_SET_TICKS     1   /* Or 0 */

#define CHART_SET_TICKS  0    /* Or 1 */

I checked the other chart types, collumn charts crop correctly but all others are as above.

Unless points are added as well,

The reason this is happening is because when a margin is used, the chart contents are clipped to the extents of that margin and not the chart background.

I’ve pushed a fix to a new chart_fix branch. It should end up in master very soon; the only reason I didn’t put it on master directly is because I’m not as familiar with that portion of the code.

Can you test it and see if the problem is resolved?

Thank you, it seems to be behaving as expected.