int main(int argc, char *argv[])
{
    // The data for the pie chart
    double data[] = {72, 18, 15, 12};

    // The depths for the sectors
    double depths[] = {30, 20, 10, 10};

    // The labels for the pie chart
    const char *labels[] = {"Sunny", "Cloudy", "Rainy", "Snowy"};

    // The icons for the sectors
    const char *icons[] = {"sun.png", "cloud.png", "rain.png", "snowy.png"};

    // Create a PieChart object of size 400 x 300 pixels
    PieChart *c = new PieChart(400, 300);

    // Use the semi-transparent palette for this chart
    c->setColors(Chart::transparentPalette);

    // Set the background to metallic light blue (CCFFFF), with a black border and 1
    // pixel 3D border effect,
    c->setBackground(Chart::metalColor(0xccccff), 0x000000, 1);

    // Set donut center at (200, 175), and outer/inner radii as 100/50 pixels
    c->setDonutSize(200, 175, 100, 50);

    // Add a title box using 15 pts Times Bold Italic font and metallic blue (8888FF)
    // background color
    c->addTitle("Weather Profile in Wonderland", "timesbi.ttf", 15)->setBackground(
        Chart::metalColor(0x8888ff));

    // Set the pie data and the pie labels
    c->setData(DoubleArray(data, sizeof(data)/sizeof(data[0])), StringArray(labels,
        sizeof(labels)/sizeof(labels[0])));

    // Add icons to the chart as a custom field
    c->addExtraField(StringArray(icons, sizeof(icons)/sizeof(icons[0])));

    // Configure the sector labels using CDML to include the icon images
    c->setLabelFormat(
        "<*block,valign=absmiddle*><*img={field0}*> <*block*>{label}\n{percent}%"
        "<*/*><*/*>");

    // Draw the pie in 3D with variable 3D depths
    c->set3D(DoubleArray(depths, sizeof(depths)/sizeof(depths[0])));

    // Set the start angle to 225 degrees may improve layout when the depths of the
    // sector are sorted in descending order, because it ensures the tallest sector
    // is at the back.
    c->setStartAngle(225);

    // Output the chart
    c->makeChart("icondonut.png");

    //free up resources
    delete c;
    return 0;
}
int main(int argc, char *argv[])
{
    // The data for the pie chart
    double data[] = {35, 30, 25, 7, 6, 5, 4, 3, 2, 1};

    // The labels for the pie chart
    const char *labels[] = {"Labor", "Production", "Facilities", "Taxes", "Misc",
        "Legal", "Insurance", "Licenses", "Transport", "Interest"};

    // Create a PieChart object of size 560 x 270 pixels, with a golden background
    // and a 1 pixel 3D border
    PieChart *c = new PieChart(560, 270, Chart::goldColor(), -1, 1);

    // Add a title box using 15 pts Times Bold Italic font and metallic pink
    // background color
    c->addTitle("Project Cost Breakdown", "timesbi.ttf", 15)->setBackground(
        Chart::metalColor(0xff9999));

    // Set the center of the pie at (280, 135) and the radius to 110 pixels
    c->setPieSize(280, 135, 110);

    // Draw the pie in 3D with 20 pixels 3D depth
    c->set3D(20);

    // Use the side label layout method
    c->setLabelLayout(Chart::SideLayout);

    // Set the label box background color the same as the sector color, with glass
    // effect, and with 5 pixels rounded corners
    TextBox *t = c->setLabelStyle();
    t->setBackground(Chart::SameAsMainColor, Chart::Transparent, Chart::glassEffect()
        );
    t->setRoundedCorners(5);

    // Set the border color of the sector the same color as the fill color. Set the
    // line color of the join line to black (0x0)
    c->setLineColor(Chart::SameAsMainColor, 0x000000);

    // Set the start angle to 135 degrees may improve layout when there are many
    // small sectors at the end of the data array (that is, data sorted in descending
    // order). It is because this makes the small sectors position near the
    // horizontal axis, where the text label has the least tendency to overlap. For
    // data sorted in ascending order, a start angle of 45 degrees can be used
    // instead.
    c->setStartAngle(135);

    // Set the pie data and the pie labels
    c->setData(DoubleArray(data, sizeof(data)/sizeof(data[0])), StringArray(labels,
        sizeof(labels)/sizeof(labels[0])));

    // Output the chart
    c->makeChart("sidelabelpie.png");

    //free up resources
    delete c;
    return 0;
}
int main(int argc, char *argv[])
{
    // The data for the pie chart
    double data[] = {72, 18, 15, 12};

    // The labels for the pie chart
    const char *labels[] = {"Labor", "Machinery", "Facilities", "Computers"};

    // The depths for the sectors
    double depths[] = {30, 20, 10, 10};

    // Create a PieChart object of size 360 x 300 pixels, with a light blue (DDDDFF)
    // background and a 1 pixel 3D border
    PieChart *c = new PieChart(360, 300, 0xddddff, -1, 1);

    // Set the center of the pie at (180, 175) and the radius to 100 pixels
    c->setPieSize(180, 175, 100);

    // Add a title box using 15 pts Times Bold Italic font and blue (AAAAFF) as
    // background color
    c->addTitle("Project Cost Breakdown", "timesbi.ttf", 15)->setBackground(0xaaaaff)
        ;

    // Set the pie data and the pie labels
    c->setData(DoubleArray(data, sizeof(data)/sizeof(data[0])), StringArray(labels,
        sizeof(labels)/sizeof(labels[0])));

    // Draw the pie in 3D with variable 3D depths
    c->set3D(DoubleArray(depths, sizeof(depths)/sizeof(depths[0])));

    // Set the start angle to 225 degrees may improve layout when the depths of the
    // sector are sorted in descending order, because it ensures the tallest sector
    // is at the back.
    c->setStartAngle(225);

    // Output the chart
    c->makeChart("multidepthpie.png");

    //free up resources
    delete c;
    return 0;
}
예제 #4
0
파일: iconpie2.cpp 프로젝트: vopl/sp
int main(int argc, char *argv[])
{
    // The data for the pie chart
    double data[] = {28, 45, 5, 1, 12};

    // The labels for the pie chart
    const char *labels[] = {"Excellent", "Good", "Bad", "Very Bad", "Neutral"};

    // The icons for the sectors
    const char *icons[] = {"laugh.png", "smile.png", "sad.png", "angry.png",
        "nocomment.png"};

    // Create a PieChart object of size 560 x 300 pixels, with a silver background,
    // black border, 1 pxiel 3D border effect and rounded corners
    PieChart *c = new PieChart(560, 300, Chart::silverColor(), 0x000000, 1);
    c->setRoundedFrame();

    // Set the center of the pie at (280, 150) and the radius to 120 pixels
    c->setPieSize(280, 150, 120);

    // Add a title box with title written in CDML, on a sky blue (A0C8FF) background
    // with glass effect
    c->addTitle(
        "<*block,valign=absmiddle*><*img=doc.png*> Customer Survey: "
        "<*font=timesi.ttf,color=000000*>Do you like our <*font,color=dd0000*>Hyper"
        "<*super*>TM<*/font*> molecules?", "timesbi.ttf", 15, 0x000080
        )->setBackground(0xa0c8ff, 0x000000, Chart::glassEffect());

    // Add a logo to the chart written in CDML as the bottom title aligned to the
    // bottom right
    c->addTitle(Chart::BottomRight,
        "<*block,valign=absmiddle*><*img=molecule.png*> <*block*><*color=FF*>"
        "<*font=timesbi.ttf,size=12*>Molecular Engineering\n"
        "<*font=arial.ttf,size=10*>Creating better molecules");

    // Set the pie data and the pie labels
    c->setData(DoubleArray(data, sizeof(data)/sizeof(data[0])), StringArray(labels,
        sizeof(labels)/sizeof(labels[0])));

    // Set 3D style
    c->set3D();

    // Use the side label layout method
    c->setLabelLayout(Chart::SideLayout);

    // Set the label background color to transparent
    c->setLabelStyle()->setBackground(Chart::Transparent);

    // Add icons to the chart as a custom field
    c->addExtraField(StringArray(icons, sizeof(icons)/sizeof(icons[0])));

    // Configure the sector labels using CDML to include the icon images
    c->setLabelFormat(
        "<*block,valign=absmiddle*><*img={field0}*> {label} ({percent|0}%)");

    // Explode the 3rd and 4th sectors as a group (index = 2 and 3)
    c->setExplodeGroup(2, 3);

    // Set the start angle to 135 degrees may improve layout when there are many
    // small sectors at the end of the data array (that is, data sorted in descending
    // order). It is because this makes the small sectors position near the
    // horizontal axis, where the text label has the least tendency to overlap. For
    // data sorted in ascending order, a start angle of 45 degrees can be used
    // instead.
    c->setStartAngle(135);

    // output the chart
    c->makeChart("iconpie2.png");

    //free up resources
    delete c;
    return 0;
}