예제 #1
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_title02.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 = 73655040;
    chart->axis_id_2 = 73656576;

    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_title_set_name(chart, "Title!");

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

    return workbook_close(workbook);
}
예제 #2
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);
}
예제 #3
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);
}
예제 #4
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);
}
예제 #5
0
/*
 * Create a worksheet with examples charts.
 */
int main() {

    lxw_workbook     *workbook  = new_workbook("chartsheet.xlsx");
    lxw_worksheet    *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chartsheet   *chartsheet = workbook_add_chartsheet(workbook, NULL);
    lxw_chart_series *series;

    /* Add a bold format to use to highlight the header cells. */
    lxw_format *bold = workbook_add_format(workbook);
    format_set_bold(bold);

    /* Write some data for the chart. */
    write_worksheet_data(worksheet, bold);

    /* Create a bar chart. */
    lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_BAR);

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");

    /* Set the name for the series instead of the default "Series 1". */
    chart_series_set_name(series, "=Sheet1!$B$1");

    /* Add a second series but leave the categories and values undefined. They
     * can be defined later using the alternative syntax shown below.  */
    series = chart_add_series(chart, NULL, NULL);

    /* Configure the series using a syntax that is easier to define programmatically. */
    chart_series_set_categories(series, "Sheet1", 1, 0, 6, 0); /* "=Sheet1!$A$2:$A$7" */
    chart_series_set_values(series,     "Sheet1", 1, 2, 6, 2); /* "=Sheet1!$C$2:$C$7" */
    chart_series_set_name_range(series, "Sheet1", 0, 2);       /* "=Sheet1!$C$1"      */

    /* Add a chart title and some axis labels. */
    chart_title_set_name(chart,        "Results of sample analysis");
    chart_axis_set_name(chart->x_axis, "Test number");
    chart_axis_set_name(chart->y_axis, "Sample length (mm)");

    /* Set an Excel chart style. */
    chart_set_style(chart, 11);

    /* Add the chart to the chartsheet. */
    chartsheet_set_chart(chartsheet, chart);

    /* Display the chartsheet as the active sheet when the workbook is opened. */
    chartsheet_activate(chartsheet);

    return workbook_close(workbook);
}
예제 #6
0
int main() {

    lxw_workbook  *workbook  = new_workbook("test_chart_font09.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 = 68825472;
    chart->axis_id_2 = 68827392;

    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 = -45, .baseline = -1};

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

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

    return workbook_close(workbook);
}
예제 #7
0
/* Create a worksheet with a chart. */
int main() {

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


    /* Add a bold format to use to highlight the header cells. */
    lxw_format *bold = workbook_add_format(workbook);
    format_set_bold(bold);

    /* Write some data for the chart. */
    worksheet_write_string(worksheet, 0, 0, "Shingle", bold);
    worksheet_write_number(worksheet, 1, 0, 105,       NULL);
    worksheet_write_number(worksheet, 2, 0, 150,       NULL);
    worksheet_write_number(worksheet, 3, 0, 130,       NULL);
    worksheet_write_number(worksheet, 4, 0, 90,        NULL);
    worksheet_write_string(worksheet, 0, 1, "Brick",   bold);
    worksheet_write_number(worksheet, 1, 1, 50,        NULL);
    worksheet_write_number(worksheet, 2, 1, 120,       NULL);
    worksheet_write_number(worksheet, 3, 1, 100,       NULL);
    worksheet_write_number(worksheet, 4, 1, 110,       NULL);

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

    /* Configure the chart. */
    lxw_chart_series *series1 = chart_add_series(chart, NULL, "Sheet1!$A$2:$A$5");
    lxw_chart_series *series2 = chart_add_series(chart, NULL, "Sheet1!$B$2:$B$5");

    chart_series_set_name(series1, "=Sheet1!$A$1");
    chart_series_set_name(series2, "=Sheet1!$B$1");

    chart_title_set_name(chart,        "Cladding types");
    chart_axis_set_name(chart->x_axis, "Region");
    chart_axis_set_name(chart->y_axis, "Number of houses");


    /* Configure an add the chart series patterns. */
    lxw_chart_pattern pattern1 = {.type = LXW_CHART_PATTERN_SHINGLE,
                                  .fg_color = 0x804000,
                                  .bg_color = 0XC68C53};

    lxw_chart_pattern pattern2 = {.type = LXW_CHART_PATTERN_HORIZONTAL_BRICK,
                                  .fg_color = 0XB30000,
                                  .bg_color = 0XFF6666};

    chart_series_set_pattern(series1, &pattern1);
    chart_series_set_pattern(series2, &pattern2);

    /* Configure and set the chart series borders. */
    lxw_chart_line line1 = {.color = 0x804000};
    lxw_chart_line line2 = {.color = 0xb30000};

    chart_series_set_line(series1, &line1);
    chart_series_set_line(series2, &line2);

    /* Widen the gap between the series/categories. */
    chart_set_series_gap(chart, 70);

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

    return workbook_close(workbook);
}
예제 #8
0
/*
 * Create a worksheet with examples charts.
 *
 */
int main() {

    lxw_workbook     *workbook  = new_workbook("chart_pie.xlsx");
    lxw_worksheet    *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart *chart ;
    lxw_chart_series *series;

    /* Add a bold format to use to highlight the header cells. */
    lxw_format *bold = workbook_add_format(workbook);
    format_set_bold(bold);

    /* Write some data for the chart. */
    write_worksheet_data(worksheet, bold);


    /*
     * Chart 1: Create a simple pie chart.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_PIE);

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$4", "=Sheet1!$B$2:$B$4");

    /* Set the name for the series instead of the default "Series 1". */
    chart_series_set_name(series, "Pie sales data");

    /* Add a chart title. */
    chart_title_set_name(chart, "Popular Pie Types");

    /* Set an Excel chart style. */
    chart_set_style(chart, 10);

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


    /*
     * Chart 2: Create a pie chart with user defined segment colors.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_PIE);

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$4", "=Sheet1!$B$2:$B$4");

    /* Set the name for the series instead of the default "Series 1". */
    chart_series_set_name(series, "Pie sales data");

    /* Add a chart title. */
    chart_title_set_name(chart, "Pie Chart with user defined colors");

    /* Add for fills for use in the chart. */
    lxw_chart_fill fill1 = {.color = 0x5ABA10};
    lxw_chart_fill fill2 = {.color = 0xFE110E};
    lxw_chart_fill fill3 = {.color = 0xCA5C05};

    /* Add some points with the above fills. */
    lxw_chart_point point1 = {.fill = &fill1};
    lxw_chart_point point2 = {.fill = &fill2};
    lxw_chart_point point3 = {.fill = &fill3};

    /* Create an array of the point objects. */
    lxw_chart_point *points[] = {&point1,
                                 &point2,
                                 &point3,
                                 NULL};

    /* Add/override the points/segments of the chart. */
    chart_series_set_points(series, points);

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


    /*
     * Chart 3: Create a pie chart with rotation of the segments.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_PIE);

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$4", "=Sheet1!$B$2:$B$4");

    /* Set the name for the series instead of the default "Series 1". */
    chart_series_set_name(series, "Pie sales data");

    /* Add a chart title. */
    chart_title_set_name(chart, "Pie Chart with segment rotation");


    /* Change the angle/rotation of the first segment. */
    chart_set_rotation(chart, 90);

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


    return workbook_close(workbook);
}
예제 #9
0
/*
 * Create a worksheet with examples charts.
 */
int main() {

    lxw_workbook     *workbook  = new_workbook("chart_data_tools.xlsx");
    lxw_worksheet    *worksheet = workbook_add_worksheet(workbook, NULL);
    lxw_chart_series *series;
    /* Add a bold format to use to highlight the header cells. */
    lxw_format *bold = workbook_add_format(workbook);
    format_set_bold(bold);

    /* Write some data for the chart. */
    write_worksheet_data(worksheet, bold);


    /*
     * Chart 1. Example with High Low Lines.
     */
    lxw_chart *chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with High-Low Lines");

    /* Add the first series to the chart. */
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add high-low lines to the chart. */
    chart_set_high_low_lines(chart, NULL);

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


    /*
     * Chart 2. Example with Drop Lines.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with Drop Lines");

    /* Add the first series to the chart. */
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add drop lines to the chart. */
    chart_set_drop_lines(chart, NULL);

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


    /*
     * Chart 3. Example with Up-Down bars.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with Up-Down bars");

    /* Add the first series to the chart. */
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add Up-Down bars to the chart. */
    chart_set_up_down_bars(chart);

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


    /*
     * Chart 4. Example with Up-Down bars with formatting.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with Up-Down bars");

    /* Add the first series to the chart. */
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add Up-Down bars to the chart, with formatting. */
    lxw_chart_line line      = {.color = LXW_COLOR_BLACK};
    lxw_chart_fill up_fill   = {.color = 0x00B050};
    lxw_chart_fill down_fill = {.color = LXW_COLOR_RED};

    chart_set_up_down_bars_format(chart, &line, &up_fill, &line, &down_fill);

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


    /*
     * Chart 5. Example with Markers and data labels.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with Data Labels and Markers");

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(         chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add series markers. */
    chart_series_set_marker_type(series, LXW_CHART_MARKER_CIRCLE);

    /* Add series data labels. */
    chart_series_set_labels(series);

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


    /*
     * Chart 6. Example with Error Bars.
     */
    chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with Error Bars");

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(         chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add error bars to show Standard Error. */
    chart_series_set_error_bars(series->y_error_bars,
                                LXW_CHART_ERROR_BAR_TYPE_STD_ERROR, 0);

    /* Add series data labels. */
    chart_series_set_labels(series);

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


    /*
     * Chart 7. Example with a trendline
     */
    chart = workbook_add_chart(workbook, LXW_CHART_LINE);

    /* Add a chart title. */
    chart_title_set_name(chart, "Chart with a Trendline");

    /* Add the first series to the chart. */
    series = chart_add_series(chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$B$2:$B$7");
    chart_add_series(         chart, "=Sheet1!$A$2:$A$7", "=Sheet1!$C$2:$C$7");

    /* Add a polynomial trendline. */
    lxw_chart_line poly_line = {.color     = LXW_COLOR_GRAY,
                                .dash_type = LXW_CHART_LINE_DASH_LONG_DASH};

    chart_series_set_trendline(series, LXW_CHART_TRENDLINE_TYPE_POLY, 3);
    chart_series_set_trendline_line(series, &poly_line);

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


    return workbook_close(workbook);
}