Graphical representation - Data Distribution [clos

2019-07-19 05:04发布

问题:

I have a data distribution that I want to show it in a c++ program (by Eclipse for example). Is there a library that I can use here? I looked for the graphics.h, but it seems to take a lot of time to build such a thing. Something like this would be great, but a simpler version would also work for me.

回答1:

Yes, you could try to play with ImageMagick. It has wrapper for a lot of other languages other than C/C++!

This little demonstration down here is enough for you to start what you want!

int main( int argc, char * argv[] )
{
    int value[ 5 ] = { 10, 20, 30, 20, 10 };

    double width( 200 ), height( 200 );

    Magick::Image chart;
    chart.size( Magick::Geometry( width, height ) );
    chart.draw( Magick::DrawableRectangle( 0.0, 0.0, width, height ) );

    chart.strokeColor( Magick::Color( 255, 255, 255 ) );
    chart.draw( Magick::DrawableLine( width * 0.1, 0.0, width * 0.1, height ) );
    chart.draw( Magick::DrawableLine( 0.0, height * 0.9, width, height * 0.9 ) );

    double W( width * 0.8 / 5.0 );

    for ( int i( 0 ); i <= 4; i++ )
    {
        double X0( width * 0.1 + i * W );
        double Y0( height * 0.9 );

        chart.draw( Magick::DrawableRectangle( X0, Y0, X0 + W, Y0 - 4.0 * value[ i ] ) );
    }

    chart.write( "chart.png" );

    return 0;
}

It creates a graphic like this:

Good luck!



标签: c++ graphics