//角表 QWidget* Widget::addAngularMeter() { // Create an AngularMeter object of size 300 x 300 pixels with transparent background AngularMeter *m = new AngularMeter(300, 300, Chart::Transparent); // Set the default text and line colors to white (0xffffff) m->setColor(Chart::TextColor, 0xffffff); m->setColor(Chart::LineColor, 0xffffff); // Center at (150, 150), scale radius = 128 pixels, scale angle 0 to 360 degrees m->setMeter(150, 150, 128, 0, 360); // Add a black (0x000000) circle with radius 148 pixels as background m->addRing(0, 148, 0x000000); // Add a ring between radii 139 and 147 pixels using the silver color with a light grey // (0xcccccc) edge as border m->addRing(139, 147, Chart::silverColor(), 0xcccccc); // Meter scale is 0 - 100, with major/minor/micro ticks every 10/5/1 units m->setScale(0, 100, 10, 5, 1); // Set the scale label style to 16pt Arial Italic. Set the major/minor/micro tick lengths to // 13/10/7 pixels pointing inwards, and their widths to 2/1/1 pixels. m->setLabelStyle("ariali.ttf", 16); m->setTickLength(-13, -10, -7); m->setLineWidth(0, 2, 1, 1); // Add a semi-transparent blue (0x7f6666ff) pointer using the default shape m->addPointer(25, 0x7f6666ff, 0x6666ff); // Add a semi-transparent red (0x7fff6666) pointer using the arrow shape m->addPointer(9, 0x7fff6666, 0xff6666)->setShape(Chart::ArrowPointer2); // Add a semi-transparent yellow (0x7fffff66) pointer using another arrow shape m->addPointer(51, 0x7fffff66, 0xffff66)->setShape(Chart::ArrowPointer); // Add a semi-transparent green (0x7f66ff66) pointer using the line shape m->addPointer(72, 0x7f66ff66, 0x66ff66)->setShape(Chart::LinePointer); // Add a semi-transparent grey (0x7fcccccc) pointer using the pencil shape m->addPointer(85, 0x7fcccccc, 0xcccccc)->setShape(Chart::PencilPointer); // Output the chart m->makeChart("angularpointer.png"); //free up resources //delete m; QWidget *_widget= new QWidget(); QChartViewer * _v= new QChartViewer(_widget); _v->setChart(m); return _widget; }
int main(int argc, char *argv[]) { // The value to display on the meter double value = 85; // Create an AugularMeter object of size 70 x 90 pixels, using black background // with a 2 pixel 3D depressed border. AngularMeter *m = new AngularMeter(70, 90, 0, 0, -2); // Use white on black color palette for default text and line colors m->setColors(Chart::whiteOnBlackPalette); // Set the meter center at (10, 45), with radius 50 pixels, and span from 135 to // 45 degress m->setMeter(10, 45, 50, 135, 45); // Set meter scale from 0 - 100, with the specified labels const char * pattern1[] = {"E", " ", " ", " ", "F"}; m->setScale(0, 100, StringArray(pattern1, sizeof(pattern1)/sizeof(pattern1[0]))); // Set the angular arc and major tick width to 2 pixels m->setLineWidth(2, 2); // Add a red zone at 0 - 15 m->addZone(0, 15, 0xff3333); // Add an icon at (25, 35) m->addText(25, 35, "<*img=gas.gif*>"); // Add a yellow (ffff00) pointer at the specified value m->addPointer(value, 0xffff00); // Output the chart m->makeChart("iconameter.png"); //free up resources delete m; return 0; }
void createChart(int img, const char *filename) { // The value to display on the meter double value = 4.75; // Create an AugularMeter object of size 110 x 110 pixels, using silver // background color with a black 2 pixel 3D depressed border. AngularMeter *m = new AngularMeter(110, 110, Chart::silverColor(), 0x000000, -2); // Set meter appearance according to a parameter if (img == 0) { // Set the meter center at bottom left corner (15, 95), with radius 85 // pixels. Meter spans from 90 - 0 degrees. m->setMeter(15, 95, 85, 90, 0); // Add a label to the meter centered at (35, 75) m->addText(35, 75, "VDC", "arialbd.ttf", 12, Chart::TextColor, Chart::Center) ; // Add a text box to show the value at top right corner (103, 7) m->addText(103, 7, m->formatValue(value, "2"), "arial.ttf", 8, 0xffffff, Chart::TopRight)->setBackground(0, 0, -1); } else if (img == 1) { // Set the meter center at top left corner (15, 15), with radius 85 pixels. // Meter spans from 90 - 180 degrees. m->setMeter(15, 15, 85, 90, 180); // Add a label to the meter centered at (35, 35) m->addText(35, 35, "AMP", "arialbd.ttf", 12, Chart::TextColor, Chart::Center) ; // Add a text box to show the value at bottom right corner (103, 103) m->addText(103, 103, m->formatValue(value, "2"), "arial.ttf", 8, 0xffffff, Chart::BottomRight)->setBackground(0, 0, -1); } else if (img == 2) { // Set the meter center at top right corner (15, 95), with radius 85 pixels. // Meter spans from 270 - 180 degrees. m->setMeter(95, 15, 85, 270, 180); // Add a label to the meter centered at (75, 35) m->addText(75, 35, "KW", "arialbd.ttf", 12, Chart::TextColor, Chart::Center); // Add a text box to show the value at bottom left corner (7, 103) m->addText(7, 103, m->formatValue(value, "2"), "arial.ttf", 8, 0xffffff, Chart::BottomLeft)->setBackground(0, 0, -1); } else { // Set the meter center at bottom right corner (95, 95), with radius 85 // pixels. Meter spans from 270 - 360 degrees. m->setMeter(95, 95, 85, 270, 360); // Add a label to the meter centered at (75, 75) m->addText(75, 75, "RPM", "arialbd.ttf", 12, Chart::TextColor, Chart::Center) ; // Add a text box to show the value at top left corner (7, 7) m->addText(7, 7, m->formatValue(value, "2"), "arial.ttf", 8, 0xffffff, Chart::TopLeft)->setBackground(0, 0, -1); } // Meter scale is 0 - 10, with a major tick every 2 units, and minor tick every 1 // unit m->setScale(0, 10, 2, 1); // Set 0 - 6 as green (99ff99) zone, 6 - 8 as yellow (ffff00) zone, and 8 - 10 as // red (ff3333) zone m->addZone(0, 6, 0x99ff99, 0x808080); m->addZone(6, 8, 0xffff00, 0x808080); m->addZone(8, 10, 0xff3333, 0x808080); // Add a semi-transparent black (80000000) pointer at the specified value m->addPointer(value, 0x80000000); // Output the chart m->makeChart(filename); //free up resources delete m; }