ChartDirector图表控件使用C++创建图表

作者:控件中国网   出处:控件中国网   2015-07-22 09:35:17   阅读:10

ChartDirector是一款应用十分广泛的图表控件,不仅支持多种图表类型,还支持多种开发语言和平台:ASP/COM/VB、.NET、JSP/Java、ColdFusion、PHP、Perl、Python、Ruby、C++,并且可应用于WEB程序和WinForm程序,这里咱们简单介绍如何使用C++创建第一个图表,具体如下:

#include "chartdir.h"

int main(int argc, char *argv[])
{
    // The data for the bar chart
    double data[] = {85, 156, 179.5, 211, 123};

    // The labels for the bar chart
    const char *labels[] = {"Mon", "Tue", "Wed", "Thu", "Fri"};

    // Create a XYChart object of size 250 x 250 pixels
    XYChart *c = new XYChart(250, 250);

    // Set the plotarea at (30, 20) and of size 200 x 200 pixels
    c->setPlotArea(30, 20, 200, 200);

    // Add a bar chart layer using the given data
    c->addBarLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))));

    // Set the labels on the x axis.
    c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0]))));

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

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

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat