翻譯|使用教程|編輯:黃竹雯|2018-12-07 11:11:44.000|閱讀 1096 次
概述:Web圖表控件ChartDirector連載教程分享之3D散點(diǎn)圖,內(nèi)附下載和鏈接。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
ChartDirector是一個(gè)非常理想的圖表工具,它擁有廣泛的圖表類型、分層架構(gòu)、實(shí)時(shí)互動(dòng)的大數(shù)據(jù)表、普遍適應(yīng)于各種應(yīng)用程序以及支持PDF和SVG圖標(biāo)等的優(yōu)點(diǎn)。此系列連載旨在介紹ChartDirector的實(shí)用教程,供大家學(xué)習(xí)討論。

此示例演示了創(chuàng)建3D散點(diǎn)圖的基本步驟:
以下代碼可在“cppdemo / threedscatter”中找到。Mf版本的代碼可在“mfcdemo / mfcdemo”中找到(僅限Windows版本)。QT版本的代碼可在“qtdemo / qtdemo”中找到。
#include "chartdir.h"
int main(int argc, char *argv[])
{
    // The XYZ data for the 3D scatter chart as 3 random data series
    RanSeries *r = new RanSeries(0);
    DoubleArray xData = r->getSeries(100, 100, -10, 10);
    DoubleArray yData = r->getSeries(100, 0, 0, 20);
    DoubleArray zData = r->getSeries(100, 100, -10, 10);
    // Create a ThreeDScatterChart object of size 720 x 600 pixels
    ThreeDScatterChart *c = new ThreeDScatterChart(720, 600);
    // Add a title to the chart using 20 points Times New Roman Italic font
    c->addTitle("3D Scatter Chart (1)  ", "timesi.ttf", 20);
    // Set the center of the plot region at (350, 280), and set width x depth x height to 360 x 360
    // x 270 pixels
    c->setPlotRegion(350, 280, 360, 360, 270);
    // Add a scatter group to the chart using 11 pixels glass sphere symbols, in which the color
    // depends on the z value of the symbol
    c->addScatterGroup(xData, yData, zData, "", Chart::GlassSphere2Shape, 11, Chart::SameAsMainColor
        );
    // Add a color axis (the legend) in which the left center is anchored at (645, 270). Set the
    // length to 200 pixels and the labels on the right side.
    c->setColorAxis(645, 270, Chart::Left, 200, Chart::Right);
    // Set the x, y and z axis titles using 10 points Arial Bold font
    c->xAxis()->setTitle("X-Axis Place Holder", "arialbd.ttf", 10);
    c->yAxis()->setTitle("Y-Axis Place Holder", "arialbd.ttf", 10);
    c->zAxis()->setTitle("Z-Axis Place Holder", "arialbd.ttf", 10);
    // Output the chart
    c->makeChart("threedscatter.png");
    //free up resources
    delete r;
    delete c;
    return 0;
}

此示例通過包含下劃線,使用替代視角和連續(xù)著色來擴(kuò)展3D散點(diǎn)圖(1)示例。
下拉線是從數(shù)據(jù)點(diǎn)下降到XY平面的線。它們有助于可視化點(diǎn)的“高度”(z坐標(biāo)),如果沒有太多數(shù)據(jù)點(diǎn),則可能很有用。
以下代碼可在“cppdemo / threedscatter”中找到。Mf版本的代碼可在“mfcdemo / mfcdemo”中找到(僅限Windows版本)。QT版本的代碼可在“qtdemo / qtdemo”中找到。
#include "chartdir.h"
int main(int argc, char *argv[])
{
    // The XYZ data for the 3D scatter chart as 3 random data series
    RanSeries *r = new RanSeries(3);
    DoubleArray xData = r->getSeries(20, 100, -10, 10);
    DoubleArray yData = r->getSeries(20, 100, -10, 10);
    DoubleArray zData = r->getSeries(20, 100, -10, 10);
    // Create a ThreeDScatterChart object of size 720 x 520 pixels
    ThreeDScatterChart *c = new ThreeDScatterChart(720, 520);
    // Add a title to the chart using 20 points Times New Roman Italic font
    c->addTitle("3D Scatter Chart (2)  ", "timesi.ttf", 20);
    // Set the center of the plot region at (350, 240), and set width x depth x height to 360 x 360
    // x 270 pixels
    c->setPlotRegion(350, 240, 360, 360, 270);
    // Set the elevation and rotation angles to 15 and 30 degrees
    c->setViewAngle(15, 30);
    // Add a scatter group to the chart using 13 pixels glass sphere symbols, in which the color
    // depends on the z value of the symbol
    ThreeDScatterGroup *g = c->addScatterGroup(xData, yData, zData, "", Chart::GlassSphere2Shape,
        13, Chart::SameAsMainColor);
    // Add grey (888888) drop lines to the symbols
    g->setDropLine(0x888888);
    // Add a color axis (the legend) in which the left center is anchored at (645, 220). Set the
    // length to 200 pixels and the labels on the right side. Use smooth gradient coloring.
    c->setColorAxis(645, 220, Chart::Left, 200, Chart::Right)->setColorGradient();
    // Set the x, y and z axis titles using 10 points Arial Bold font
    c->xAxis()->setTitle("X-Axis Place Holder", "arialbd.ttf", 10);
    c->yAxis()->setTitle("Y-Axis Place Holder", "arialbd.ttf", 10);
    c->zAxis()->setTitle("Z-Axis Place Holder", "arialbd.ttf", 10);
    // Output the chart
    c->makeChart("threedscatter2.png");
    //free up resources
    delete r;
    delete c;
    return 0;
}
更多實(shí)用教程將會(huì)以連載的形式展現(xiàn),敬請(qǐng)關(guān)注~
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@ke049m.cn