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;
}