示例#1
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_bar03.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart1    = workbook_add_chart(workbook, LXW_CHART_BAR);
    lxw_chart     *chart2    = workbook_add_chart(workbook, LXW_CHART_BAR);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart1->axis_id_1 = 64265216;
    chart1->axis_id_2 = 64447616;

    chart2->axis_id_1 = 86048128;
    chart2->axis_id_2 = 86058112;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col] , NULL);

    chart_add_series(chart1,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart1,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    worksheet_insert_chart(worksheet, CELL("E9"), chart1);

    chart_add_series(chart2,
         "=Sheet1!$A$1:$A$4",
         "=Sheet1!$B$1:$B$4"
    );

    chart_add_series(chart2,
         "=Sheet1!$A$1:$A$4",
         "=Sheet1!$C$1:$C$4"
    );

    worksheet_insert_chart(worksheet, CELL("F25"), chart2);


    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook   = new_workbook("test_chart_order01.xlsx");
    lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
    lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
    lxw_worksheet *worksheet3 = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart1     = workbook_add_chart(workbook, LXW_CHART_COLUMN);
    lxw_chart     *chart2     = workbook_add_chart(workbook, LXW_CHART_BAR);
    lxw_chart     *chart3     = workbook_add_chart(workbook, LXW_CHART_LINE);
    lxw_chart     *chart4     = workbook_add_chart(workbook, LXW_CHART_PIE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart1->axis_id_1 = 54976896;
    chart1->axis_id_2 = 54978432;

    chart2->axis_id_1 = 54310784;
    chart2->axis_id_2 = 54312320;

    chart3->axis_id_1 = 69816704;
    chart3->axis_id_2 = 69818240;

    chart4->axis_id_1 = 69816704;
    chart4->axis_id_2 = 69818240;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++) {
            worksheet_write_number(worksheet1, row, col, data[row][col], NULL);
            worksheet_write_number(worksheet2, row, col, data[row][col], NULL);
            worksheet_write_number(worksheet3, row, col, data[row][col], NULL);
        }

    chart_add_series(chart1, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart2, NULL, "=Sheet2!$A$1:$A$5");
    chart_add_series(chart3, NULL, "=Sheet3!$A$1:$A$5");
    chart_add_series(chart4, NULL, "=Sheet1!$B$1:$B$5");

    worksheet_insert_chart(worksheet1, CELL("E9"),  chart1);
    worksheet_insert_chart(worksheet2, CELL("E9"),  chart2);
    worksheet_insert_chart(worksheet3, CELL("E9"),  chart3);
    worksheet_insert_chart(worksheet1, CELL("E24"), chart4);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_format19.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN_STACKED);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 56127488;
    chart->axis_id_2 = 57455360;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    lxw_chart_series *series = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    chart_series_set_labels(series);
    chart_series_set_labels_position(series, LXW_CHART_LABEL_POSITION_INSIDE_BASE);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_display_units11.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 69559424;
    chart->axis_id_2 = 69560960;

    worksheet_write_number(worksheet, 0, 0, 10000000, NULL);
    worksheet_write_number(worksheet, 1, 0, 20000000, NULL);
    worksheet_write_number(worksheet, 2, 0, 30000000, NULL);
    worksheet_write_number(worksheet, 3, 0, 20000000, NULL);
    worksheet_write_number(worksheet, 4, 0, 10000000, NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");

    chart_axis_set_display_units(chart->y_axis, LXW_CHART_AXIS_UNITS_HUNDREDS);


    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook   = new_workbook("test_chart_bar02.xlsx");
    lxw_worksheet *worksheet1 = workbook_add_worksheet(workbook, NULL);
    lxw_worksheet *worksheet2 = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart      = workbook_add_chart(workbook, LXW_CHART_BAR);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 93218304;
    chart->axis_id_2 = 93219840;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet2, row, col, data[row][col] , NULL);

    worksheet_write_string(worksheet1, CELL("A1"), "Foo" , NULL);

    chart_add_series(chart, "Sheet2!$A$1:$A$5", "Sheet2!$B$1:$B$5");
    chart_add_series(chart, "Sheet2!$A$1:$A$5", "Sheet2!$C$1:$C$5");


    worksheet_insert_chart(worksheet2, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_axis29.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 45444480;
    chart->axis_id_2 = 47402368;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    lxw_chart_font font1 = {.rotation = -90, .baseline = -1};
    chart_axis_set_num_font(chart->x_axis, &font1);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_doughnut02.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_DOUGHNUT);

    uint8_t data[3][2] = {
        {2,  60},
        {4,  30},
        {6,  10},
    };

    int row, col;
    for (row = 0; row < 3; row++)
        for (col = 0; col < 2; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$3",
         "=Sheet1!$B$1:$B$3"
    );

    chart_set_hole_size(chart, 10);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_data_labels13.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_PIE);

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");

    chart_series_set_labels(series1);
    chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_INSIDE_END);
    chart_series_set_labels_leader_line(series1);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#9
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_axis06.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_PIE);

    uint8_t data[3][2] = {
        {2,  60},
        {4,  30},
        {6,  10},
    };

    int row, col;
    for (row = 0; row < 3; row++)
        for (col = 0; col < 2; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, 
         "=Sheet1!$A$1:$A$3",
         "=Sheet1!$B$1:$B$3"
    );

    chart_title_set_name(chart, "Title");

    /* Axis formatting should be igmored. */
    chart_axis_set_name(chart->x_axis, "XXX");
    chart_axis_set_name(chart->y_axis, "YYY");

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_blank03.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 44253568;
    chart->axis_id_2 = 44269952;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    chart_show_blanks_as(chart, LXW_CHART_BLANKS_AS_CONNECTED);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_legend03.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 93548928;
    chart->axis_id_2 = 93550464;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    chart_legend_set_position(chart, LXW_CHART_LEGEND_TOP_RIGHT);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#12
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_axis25.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 47471232;
    chart->axis_id_2 = 48509696;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    chart_axis_set_num_format(chart->x_axis, "[$¥-411]#,##0.00");
    chart_axis_set_num_format(chart->y_axis, "0.00%");

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_column05.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, "Foo");
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 47292800;
    chart->axis_id_2 = 47295104;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col] , NULL);

    chart_add_series(chart, NULL, "=Foo!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Foo!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Foo!$C$1:$C$5");

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_title01.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    lxw_chart_series *series;

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 46165376;
    chart->axis_id_2 = 54462720;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    series = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");

    chart_series_set_name(series, "Foo");
    chart_title_off(chart);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#15
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_bar22.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_BAR);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 43706240;
    chart->axis_id_2 = 43727104;


    worksheet_write_string(worksheet, 0, 1, "Series 1", NULL);
    worksheet_write_string(worksheet, 0, 2, "Series 2", NULL);
    worksheet_write_string(worksheet, 0, 3, "Series 3", NULL);

    worksheet_write_string(worksheet, 1, 0, "Category 1", NULL);
    worksheet_write_string(worksheet, 2, 0, "Category 2", NULL);
    worksheet_write_string(worksheet, 3, 0, "Category 3", NULL);
    worksheet_write_string(worksheet, 4, 0, "Category 4", NULL);

    worksheet_write_number(worksheet, 1, 1, 4.3, NULL);
    worksheet_write_number(worksheet, 2, 1, 2.5, NULL);
    worksheet_write_number(worksheet, 3, 1, 3.5, NULL);
    worksheet_write_number(worksheet, 4, 1, 4.5, NULL);

    worksheet_write_number(worksheet, 1, 2, 2.4, NULL);
    worksheet_write_number(worksheet, 2, 2, 4.5, NULL);
    worksheet_write_number(worksheet, 3, 2, 1.8, NULL);
    worksheet_write_number(worksheet, 4, 2, 2.8, NULL);

    worksheet_write_number(worksheet, 1, 3, 2,   NULL);
    worksheet_write_number(worksheet, 2, 3, 2,   NULL);
    worksheet_write_number(worksheet, 3, 3, 3,   NULL);
    worksheet_write_number(worksheet, 4, 3, 5,   NULL);

    worksheet_set_column(worksheet, COLS("A:D"), 11, NULL);

    chart_add_series(chart,
         "=Sheet1!$A$2:$A$5",
         "=Sheet1!$B$2:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$2:$A$5",
         "=Sheet1!$C$2:$C$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$2:$A$5",
         "=Sheet1!$D$2:$D$5"
    );

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#16
0
/* Create a worksheet with a chart. */
int main() {

    lxw_workbook  *workbook  = new_workbook("chart_fonts.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);

    /* Write some data for the chart. */
    worksheet_write_number(worksheet, 0, 0, 10, NULL);
    worksheet_write_number(worksheet, 1, 0, 40, NULL);
    worksheet_write_number(worksheet, 2, 0, 50, NULL);
    worksheet_write_number(worksheet, 3, 0, 20, NULL);
    worksheet_write_number(worksheet, 4, 0, 10, NULL);
    worksheet_write_number(worksheet, 5, 0, 50, NULL);

    /* Create a chart object. */
    lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Configure the chart. */
    chart_add_series(chart, NULL, "Sheet1!$A$1:$A$6");

    /* Create some fonts to use in the chart.  */
    lxw_chart_font font1 = {.name = "Calibri", .color = LXW_COLOR_BLUE};
    lxw_chart_font font2 = {.name = "Courier", .color = 0x92D050};
    lxw_chart_font font3 = {.name = "Arial",   .color = 0x00B0F0};
    lxw_chart_font font4 = {.name = "Century", .color = LXW_COLOR_RED};
    lxw_chart_font font5 = {.rotation = -30};
    lxw_chart_font font6 = {.bold      = LXW_TRUE,
                            .italic    = LXW_TRUE,
                            .underline = LXW_TRUE,
                            .color     = 0x7030A0};

    /* Write the chart title with a font. */
    chart_title_set_name(chart, "Test Results");
    chart_title_set_name_font(chart, &font1);

    /* Write the Y axis with a font. */
    chart_axis_set_name(chart->y_axis, "Units");
    chart_axis_set_name_font(chart->y_axis, &font2);
    chart_axis_set_num_font(chart->y_axis, &font3);

    /* Write the X axis with a font. */
    chart_axis_set_name(chart->x_axis, "Month");
    chart_axis_set_name_font(chart->x_axis, &font4);
    chart_axis_set_num_font(chart->x_axis, &font5);

    /* Display the chart legend at the bottom of the chart. */
    chart_legend_set_position(chart, LXW_CHART_LEGEND_BOTTOM);
    chart_legend_set_font(chart, &font6);

    /* Insert the chart into the worksheet. */
    worksheet_insert_chart(worksheet, CELL("C1"), chart);

    return workbook_close(workbook);
}
示例#17
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_font03.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_BAR);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 45704704;
    chart->axis_id_2 = 45716224;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    lxw_chart_font font1 = {.italic = LXW_TRUE};
    lxw_chart_font font2 = {.bold = LXW_TRUE, .italic = LXW_TRUE};
    lxw_chart_font font3 = {.size = 11, .bold = LXW_TRUE, .italic = LXW_TRUE};
    lxw_chart_font font4 = {.size = 9, .italic = LXW_TRUE};

    chart_title_set_name(chart, "Title");
    chart_title_set_name_font(chart, &font1);

    chart_axis_set_name(chart->x_axis, "XXX");
    chart_axis_set_name_font(chart->x_axis, &font1);

    chart_axis_set_name(chart->y_axis, "YYY");
    chart_axis_set_name_font(chart->y_axis, &font2);

    chart_axis_set_num_font(chart->x_axis, &font3);
    chart_axis_set_num_font(chart->y_axis, &font4);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_format27.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 108645376;
    chart->axis_id_2 = 108655360;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series = chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    lxw_chart_line line = {.color     = LXW_COLOR_RED,
                           .width     = 1,
                           .dash_type = LXW_CHART_LINE_DASH_LONG_DASH};

    chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_POLY, 2);
    chart_series_set_trendline_line(series, &line);
    chart_series_set_trendline_name(series, "My trend name");
    chart_series_set_trendline_forecast(series, 0.5, 0.5);
    chart_series_set_trendline_equation(series);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_format03.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 46175744;
    chart->axis_id_2 = 46319488;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series1 = chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    lxw_chart_line line = {.color = LXW_COLOR_YELLOW};
    lxw_chart_fill fill = {.color = LXW_COLOR_RED};

    chart_series_set_line(series1, &line);
    chart_series_set_fill(series1, &fill);

    /* Set the properties twice to check for memory leaks. */
    chart_series_set_line(series1, &line);
    chart_series_set_fill(series1, &fill);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#20
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_format07.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 46163840;
    chart->axis_id_2 = 46175360;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series = chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    lxw_chart_line line = {.color = LXW_COLOR_YELLOW};
    lxw_chart_fill fill = {.color = LXW_COLOR_RED};

    chart_series_set_marker_type(series, LXW_CHART_MARKER_SQUARE);
    chart_series_set_marker_size(series, 5);

    chart_series_set_marker_line(series, &line);
    chart_series_set_marker_fill(series, &fill);


    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#21
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_format24.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 115374720;
    chart->axis_id_2 = 115389568;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );


    lxw_chart_fill fill1 = {.color = LXW_COLOR_YELLOW, .transparency = 75};
    lxw_chart_fill fill2 = {.color = LXW_COLOR_RED,    .transparency = 25};

    chart_chartarea_set_fill(chart, &fill1);
    chart_plotarea_set_fill(chart, &fill2);


    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_blank04.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 42268928;
    chart->axis_id_2 = 42990208;

    /* Leave some blanks in the default test data. */

    worksheet_write_number(worksheet, 0, 0, 1,     NULL);
    worksheet_write_number(worksheet, 1, 0, 2,     NULL);

    worksheet_write_number(worksheet, 3, 0, 4,     NULL);
    worksheet_write_number(worksheet, 4, 0, 5,     NULL);

    worksheet_write_number(worksheet, 0, 1, 2,     NULL);
    worksheet_write_number(worksheet, 1, 1, 4,     NULL);

    worksheet_write_number(worksheet, 3, 1, 8,     NULL);
    worksheet_write_number(worksheet, 4, 1, 10,    NULL);

    worksheet_write_number(worksheet, 0, 2, 3,     NULL);
    worksheet_write_number(worksheet, 1, 2, 6,     NULL);

    worksheet_write_number(worksheet, 3, 2, 12,    NULL);
    worksheet_write_number(worksheet, 4, 2, 15,    NULL);



    chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    chart_show_blanks_as(chart, LXW_CHART_BLANKS_AS_CONNECTED);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_format15.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 42401792;
    chart->axis_id_2 = 42403712;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series = chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_LINEAR, 0);

    int16_t names[] = {2, 0, -1};
    chart_legend_delete_series(chart, names);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#24
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_axis13.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_SCATTER);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 54045312;
    chart->axis_id_2 = 54043776;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    chart_axis_set_min(chart->x_axis, 0);
    chart_axis_set_max(chart->x_axis, 6);
    chart_axis_set_min(chart->y_axis, 0);
    chart_axis_set_max(chart->y_axis, 16);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#25
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_high_low_lines02.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 61180928;
    chart->axis_id_2 = 63898368;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_line line = {.color     = LXW_COLOR_RED,
                           .dash_type = LXW_CHART_LINE_DASH_SQUARE_DOT};

    chart_set_high_low_lines(chart, &line);

    chart_add_series(chart, 
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart, 
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#26
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_str02.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_SCATTER);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 41671680;
    chart->axis_id_2 = 41669376;

    worksheet_write_number(worksheet, 0, 0, 1,     NULL);
    worksheet_write_number(worksheet, 1, 0, 2,     NULL);
    worksheet_write_string(worksheet, 2, 0, "Foo", NULL);
    worksheet_write_number(worksheet, 3, 0, 4,     NULL);
    worksheet_write_number(worksheet, 4, 0, 5,     NULL);

    worksheet_write_number(worksheet, 0, 1, 2,     NULL);
    worksheet_write_number(worksheet, 1, 1, 4,     NULL);
    worksheet_write_string(worksheet, 2, 1, "Bar", NULL);
    worksheet_write_number(worksheet, 3, 1, 8,     NULL);
    worksheet_write_number(worksheet, 4, 1, 10,    NULL);

    worksheet_write_number(worksheet, 0, 2, 3,     NULL);
    worksheet_write_number(worksheet, 1, 2, 6,     NULL);
    worksheet_write_string(worksheet, 2, 2, "Baz", NULL);
    worksheet_write_number(worksheet, 3, 2, 12,    NULL);
    worksheet_write_number(worksheet, 4, 2, 15,    NULL);

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );
    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
示例#27
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_column07.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_COLUMN);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 68810240;
    chart->axis_id_2 = 68811776;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series1 = chart_add_series(chart, NULL, "=(Sheet1!$A$1:$A$2,Sheet1!$A$4:$A$5)");

    worksheet_insert_chart(worksheet, CELL("E9"), chart);


    /* Add the cached data for testing. */
    uint8_t test_data[4][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {4, 8,  12},
        {5, 10, 15}
    };

    lxw_chart_add_data_cache(series1->values, test_data[0], 4, 3, 0);


    return workbook_close(workbook);
}
示例#28
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_chartarea05.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_PIE);

    uint8_t data[3][2] = {
        {2,  60},
        {4,  30},
        {6,  10},
    };

    int row, col;
    for (row = 0; row < 3; row++)
        for (col = 0; col < 2; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$3",
         "=Sheet1!$B$1:$B$3"
    );

    
    lxw_chart_line line1 = {.dash_type = LXW_CHART_LINE_DASH_LONG_DASH, .color = 0xFFFF00};
    lxw_chart_line line2 = {.dash_type = LXW_CHART_LINE_DASH_DASH_DOT};

    lxw_chart_fill fill1 = {.color = 0x92D050};
    lxw_chart_fill fill2 = {.color = 0xFFC000};

    chart_chartarea_set_line(chart, &line1);
    chart_chartarea_set_fill(chart, &fill1);

    /* This should be ignored for a pie chart. */
    chart_plotarea_set_line(chart, &line2);
    chart_plotarea_set_fill(chart, &fill2);


    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_scatter09.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_SCATTER_SMOOTH_WITH_MARKERS);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 45953024;
    chart->axis_id_2 = 45954944;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series = chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$B$1:$B$5"
    );

    chart_add_series(chart,
         "=Sheet1!$A$1:$A$5",
         "=Sheet1!$C$1:$C$5"
    );

    chart_series_set_smooth(series, LXW_FALSE);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_data_labels05.xlsx");
    lxw_worksheet *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart     *chart     = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* For testing, copy the randomly generated axis ids in the target file. */
    chart->axis_id_1 = 45678592;
    chart->axis_id_2 = 45680128;

    uint8_t data[5][3] = {
        {1, 2,  3},
        {2, 4,  6},
        {3, 6,  9},
        {4, 8,  12},
        {5, 10, 15}
    };

    int row, col;
    for (row = 0; row < 5; row++)
        for (col = 0; col < 3; col++)
            worksheet_write_number(worksheet, row, col, data[row][col], NULL);

    lxw_chart_series *series1 = chart_add_series(chart, NULL, "=Sheet1!$A$1:$A$5");
    lxw_chart_series *series2 = chart_add_series(chart, NULL, "=Sheet1!$B$1:$B$5");
    lxw_chart_series *series3 = chart_add_series(chart, NULL, "=Sheet1!$C$1:$C$5");

    chart_series_set_labels(series1);
    chart_series_set_labels(series2);
    chart_series_set_labels(series3);
    chart_series_set_labels_position(series1, LXW_CHART_LABEL_POSITION_RIGHT);
    chart_series_set_labels_position(series2, LXW_CHART_LABEL_POSITION_ABOVE);
    chart_series_set_labels_position(series3, LXW_CHART_LABEL_POSITION_BELOW);

    worksheet_insert_chart(worksheet, CELL("E9"), chart);

    return workbook_close(workbook);
}