翻譯|使用教程|編輯:黃竹雯|2018-12-20 13:52:21.000|閱讀 466 次
概述:Web圖表控件ChartDirector連載教程分享之條形圖描影,內(nèi)附下載和鏈接。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
ChartDirector是一個非常理想的圖表工具,它擁有廣泛的圖表類型、分層架構(gòu)、實時互動的大數(shù)據(jù)表、普遍適應(yīng)于各種應(yīng)用程序以及支持PDF和SVG圖標等的優(yōu)點。此系列連載旨在介紹ChartDirector的實用教程,供大家學(xué)習(xí)討論。
此示例演示了條形圖的柔性光照效果、繪圖區(qū)域背景的漸變顏色以及在軸標簽之間放置軸刻度。
柔和的燈光是一種特殊的陰影效果,看起來像漸變色。在該示例中,柔和的照明效果被用到條行圖上,光從左邊方向發(fā)出。具體方法是:
以下代碼可在“cppdemo / softlightbar”中找到。MFC版本的代碼可在“mfcdemo”中找到(僅限Windows版本)。QT版本的代碼可在“qtdemo”中找到。
#include "chartdir.h" int main(int argc, char *argv[]) { // The data for the bar chart double data[] = {450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700}; // The labels for the bar chart const char *labels[] = {"1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005"}; // Create a XYChart object of size 600 x 360 pixels XYChart *c = new XYChart(600, 360); // Add a title to the chart using 18pt Times Bold Italic font c->addTitle("Annual Revenue for Star Tech", "timesbi.ttf", 18); // Set the plotarea at (60, 40) and of size 500 x 280 pixels. Use a vertical gradient color from // light blue (eeeeff) to deep blue (0000cc) as background. Set border and grid lines to white // (ffffff). c->setPlotArea(60, 40, 500, 280, c->linearGradientColor(60, 40, 60, 280, 0xeeeeff, 0x0000cc), -1, 0xffffff, 0xffffff); // Add a multi-color bar chart layer using the supplied data. Use soft lighting effect with // light direction from left. c->addBarLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), IntArray(0, 0) )->setBorderColor(Chart::Transparent, Chart::softLighting(Chart::Left)); // Set x axis labels using the given labels c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0])))); // Draw the ticks between label positions (instead of at label positions) c->xAxis()->setTickOffset(0.5); // Add a title to the y axis with 10pt Arial Bold font c->yAxis()->setTitle("USD (millions)", "arialbd.ttf", 10); // Set axis label style to 8pt Arial Bold c->xAxis()->setLabelStyle("arialbd.ttf", 8); c->yAxis()->setLabelStyle("arialbd.ttf", 8); // Set axis line width to 2 pixels c->xAxis()->setWidth(2); c->yAxis()->setWidth(2); // Output the chart c->makeChart("softlightbar.png"); //free up resources delete c; return 0; }
此示例演示了條形圖的玻璃著色效果、繪圖區(qū)域背景的漸變顏色以及繪圖區(qū)域兩側(cè)的軸標簽。
玻璃型描影是一種復(fù)雜的陰影效果,可以實現(xiàn)有色玻璃或半透明塑料材料的外觀和感覺。這種效應(yīng)涉及材料內(nèi)部反射和折射引起的眩光和光照變化。具體方法如下:
以下代碼可在“cppdemo / glasslightbar”中找到。MFC版本的代碼可在“mfcdemo”中找到(僅限Windows版本)。QT版本的代碼可在“qtdemo”中找到。
#include "chartdir.h" int main(int argc, char *argv[]) { // The data for the bar chart double data[] = {450, 560, 630, 800, 1100, 1350, 1600, 1950, 2300, 2700}; // The labels for the bar chart const char *labels[] = {"1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005"}; // Create a XYChart object of size 600 x 360 pixels XYChart *c = new XYChart(600, 360); // Set the plotarea at (60, 40) and of size 480 x 280 pixels. Use a vertical gradient color from // light blue (eeeeff) to deep blue (0000cc) as background. Set border and grid lines to white // (ffffff). c->setPlotArea(60, 40, 480, 280, c->linearGradientColor(60, 40, 60, 280, 0xeeeeff, 0x0000cc), -1, 0xffffff, 0xffffff); // Add a title to the chart using 18pt Times Bold Italic font c->addTitle("Annual Revenue for Star Tech", "timesbi.ttf", 18); // Add a multi-color bar chart layer using the supplied data. Use glass lighting effect with // light direction from the left. c->addBarLayer(DoubleArray(data, (int)(sizeof(data) / sizeof(data[0]))), IntArray(0, 0) )->setBorderColor(Chart::Transparent, Chart::glassEffect(Chart::NormalGlare, Chart::Left)); // Set the x axis labels c->xAxis()->setLabels(StringArray(labels, (int)(sizeof(labels) / sizeof(labels[0])))); // Show the same scale on the left and right y-axes c->syncYAxis(); // Set the left y-axis and right y-axis title using 10pt Arial Bold font c->yAxis()->setTitle("USD (millions)", "arialbd.ttf", 10); c->yAxis2()->setTitle("USD (millions)", "arialbd.ttf", 10); // Set all axes to transparent c->xAxis()->setColors(Chart::Transparent); c->yAxis()->setColors(Chart::Transparent); c->yAxis2()->setColors(Chart::Transparent); // Set the label styles of all axes to 8pt Arial Bold font c->xAxis()->setLabelStyle("arialbd.ttf", 8); c->yAxis()->setLabelStyle("arialbd.ttf", 8); c->yAxis2()->setLabelStyle("arialbd.ttf", 8); // Output the chart c->makeChart("glasslightbar.png"); //free up resources delete c; return 0; }
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn