How to change the color of the axis and label text of a chart in v8

Description

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

VisualStudio Simulator

What LVGL version are you using?

v8

What do you want to achieve?

Change the color of axis (includse tick and label text)
For example, I want to have a chart with red axis and red label text.
BTW, Could the primary axis and the second be set with different color ?

What have you tried so far?

set the text color of a style and add it to the chart obj.
But it does not work!

Code to reproduce

Add a code snippet which can run in the simulator. It should contain only the relevant code that compiles without errors when separated from your main code base.

The code block(s) should be formatted like:

/*You code here*/
static lv_style_t style_chart_op;
lv_style_init(&style_chart_op);
lv_style_set_text_color(&style_chart_op, lv_color_make(255, 0, 0));

chart_op = lv_chart_create(parent);
    //lv_obj_add_style(chart_op, &style_chart_op,0);
    lv_obj_set_width(chart_op, lv_pct(92));//640
    lv_obj_set_height(chart_op, lv_pct(90) );//300
    lv_obj_set_style_opa(chart_op, 150, 0);
    lv_obj_set_style_bg_color(chart_op, lv_color_make(200,50,10), 0);
    lv_obj_set_style_bg_grad_color(chart_op, lv_color_make(10, 100, 200), 0);
    lv_obj_set_style_bg_grad_dir(chart_op, LV_GRAD_DIR_VER,0);
    lv_obj_set_scrollbar_mode(chart_op, LV_SCROLL_SNAP_NONE);
    lv_obj_add_style(chart_op, &style_chart_op, 0);   

Screenshot and/or video

If possible, add screenshots and/or videos about the current state.

chart

I have modified all of the line color in chart (includes the grid line in chart)via following

else if (code == LV_EVENT_DRAW_PART_BEGIN){
        lv_obj_draw_part_dsc_t* dsc_chart = lv_event_get_draw_part_dsc(e);
        if (dsc_chart->part = LV_PART_TICKS) {
            dsc_chart->line_dsc->color = lv_color_make(255, 0, 0);
            
        }
    }

charts
I think that the color of label text can be set by the same way but I can not find that exactly.
But It can not set axis with different color.

Thank you very much!

I have find solution to set axis with different color:

    else if (code == LV_EVENT_DRAW_PART_BEGIN){
        lv_obj_draw_part_dsc_t* dsc_chart = lv_event_get_draw_part_dsc(e);
        if (dsc_chart->part = LV_PART_TICKS) {
            if (dsc_chart->id == 0) {
                dsc_chart->line_dsc->color = lv_color_make(255, 0, 0);
            }
            else if (dsc_chart->id == 1) {
                dsc_chart->line_dsc->color = lv_color_make(0, 0, 255);
            }
            else if (dsc_chart->id == 2) {
                dsc_chart->line_dsc->color = lv_color_make(0, 0, 0);
            }
        }
    }

the axis can be distinguished via dsc_chart->id, hence the color of different axis can be set Individually.
chart3
But I can not find the way to change the color of label text

I think you can do this by just adding a style to LV_PART_TICKS:

    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_line_color(&style, lv_color_make(255, 0, 0));
    lv_style_set_text_color(&style, lv_color_make(255, 0, 0));
    lv_obj_add_style(chart_op, &style, LV_PART_TICKS);
1 Like

Thank you for your suggest, it can modify the color of the label text!