本帖最后由 shizhiqiang123 于 2011-05-11 10:47:20 编辑

解决方案 »

  1.   

    http://localhost/C:/Documents%20and%20Settings/Administrator.PC917/桌面/222.jpg
      

  2.   

    仔细研究下gd,无非就是按x轴增加计算对应的y,然后设置那个像素为某种颜色
      

  3.   

    前天看到的代码,你拷到自己的服务器上试下,页面最后一个就是波形图!
    example.php<div style="width: 730px; margin: 20px auto; font-family:sans-serif;">
    <?php
    /** Include class */
    include( 'GoogChart.class.php' );/** Create chart */
    $chart = new GoogChart();
    /* Example 1
    Pie chart*/// Set graph data
    $data = array(
    'IE7' => 22,
    'IE6' => 30.7,
    'IE5' => 1.7,
    'Firefox' => 36.5,
    'Mozilla' => 1.1,
    'Safari' => 2,
    'Opera' => 1.4,
    );// Set graph colors
    $color = array(
    '#99C754',
    '#54C7C5',
    '#999999',
    );/* # Chart 1 # */
    echo '<h2>Pie chart</h2>';
    $chart->setChartAttrs( array(
    'type' => 'pie',
    'title' => 'Browser et 2008',
    'data' => $data,
    'size' => array( 400, 300 ),
    'color' => $color
    ));
    // Print chart
    echo $chart;
    /* Example 2
    Bar graph
    Multiple data*/// Set multiple graph data
    $dataMultiple = array( 
    'February 2008' => array(
    'IE7' => 22,
    'IE6' => 30.7,
    'IE5' => 1.7,
    'Firefox' => 36.5,
    'Mozilla' => 1.1,
    'Safari' => 2,
    'Opera' => 1.4,
    ),
    'January 2008' => array(
    'IE7' => 22,
    'IE6' => 30.7,
    'IE5' => 1.7,
    'Firefox' => 36.5,
    'Mozilla' => 1.1,
    'Safari' => 2,
    'Opera' => 1.4,
    ),
    );/* # Chart 2 # */
    echo '<h2>Vertical Bar</h2>';
    $chart->setChartAttrs( array(
    'type' => 'bar-vertical',
    'title' => 'Browser et 2008',
    'data' => $dataMultiple,
    'size' => array( 550, 200 ),
    'color' => $color,
    'labelsXY' => true,
    ));
    // Print chart
    echo $chart;/* Example 3
    Timeline
    Multiple data*/// Set timeline graph data
    $dataTimeline = array( 
    '2007' => array(
    'January' => 31.0,
    'February' => 31.2,
    'March' => 31.8,
    'April' => 32.9,
    'May' => 33.7,
    'June' => 34.0,
    'July' => 34.5,
    'August' => 34.9,
    'September' => 35.4,
    'Oktober' => 36.0,
    'November' => 36.3,
    'December' => 36.3,
    ),
    '2006' => array(
    'January' => 25.0,
    'February' => 24.5,
    'March' => 24.5,
    'April' => 22.9,
    'May' => 22.9,
    'June' => 25.5,
    'July' => 25.5,
    'August' => 24.9,
    'September' => 27.3,
    'Oktober' => 27.3,
    'November' => 29.9,
    'December' => 29.9,
    ),
    '2005' => array(
    'January' => 15.0,
    'February' => 14.5,
    'March' => 14.5,
    'April' => 12.9,
    'May' => 12.9,
    'June' => 15.5,
    'July' => 15.5,
    'August' => 14.9,
    'September' => 17.3,
    'Oktober' => 17.3,
    'November' => 19.9,
    'December' => 19.9,
    ),
    );/* # Chart 3 # */
    echo '<h2>Timeline</h2>';
    $chart->setChartAttrs( array(
    'type' => 'sparkline',
    'title' => 'Firefox et share (%) 2006-07',
    'data' => $dataTimeline,
    'size' => array( 600, 200 ),
    'color' => $color,
    'labelsXY' => true,
    'fill' => array( '#eeeeee', '#aaaaaa' ),
    ));
    // Print chart
    echo $chart;
    ?>
    </div>GoogChart.class.php<?php#
    # Chart
    #
    # by Ludwig Pettersson
    # <http://luddep.se>
    #
    # With help from Fredrik Holmstr鰉
    # <http://loveandtheft.org/>
    ## Copyright (c) 2008 Ludwig Pettersson# Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to deal
    # in the Software without restriction, including without limitation the rights
    # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    # copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:# The above copyright notice and this permission notice shall be included in
    # all copies or substantial portions of the Software.# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    # THE SOFTWARE.class GoogChart
    {
    // Constants
    const BASE = 'http://chart.apis.google.com/chart?'; // Variables
    protected $types = array(
    'pie' => 'p',
    'line' => 'lc',
    'sparkline' => 'ls',
    'bar-horizontal' => 'bhg',
    'bar-vertical' => 'bvg',
    ); protected $type;
    protected $title;
    protected $data = array();
    protected $size = array();
    protected $color = array();
    protected $fill = array();
    protected $labelsXY = false;
    protected $legend;
    protected $useLegend = true;
    protected $background = 'a,s,ffffff'; protected $query = array(); // debug
    public $debug = array(); // Return string
    public function __toString()
    {
    return $this->display();
    }
    /** Create chart
    */
    protected function display()
    {
    // Create query
    $this->query = array(
    'cht'  => $this->types[strtolower($this->type)], // Type
    'chtt'  => $this->title, // Title
    'chd' => 't:'.$this->data['values'], // Data
    'chl'   => $this->data['names'], // Data labels
    'chdl' => ( ($this->useLegend) && (is_array($this->legend)) ) ? implode('|',$this->legend) : null, // Data legend
    'chs'   => $this->size[0].'x'.$this->size[1], // Size
    'chco'   => preg_replace( '/[#]+/', '', implode(',',$this->color)), // Color ( Remove # from string )
    'chm'   => preg_replace( '/[#]+/', '', implode('|',$this->fill)),   // Fill ( Remove # from string )
    'chxt' => ( $this->labelsXY == true) ? 'x,y' : null, // X & Y axis labels
    'chf' => preg_replace( '/[#]+/', '', $this->background), // Background color ( Remove # from string )
    ); // Return chart
    return $this->img(
    GoogChart::BASE.http_build_query($this->query),
    $this->title
    );
    } /** Set attributes
    */
    public function setChartAttrs( $attrs )
    {
    // debug
    $this->debug[] = $attrs; foreach( $attrs as $key => $value )
    {
    $this->{"set$key"}($value);
    }
    } /** Set type
    */
    protected function setType( $type )
    {
    $this->type = $type;
    }
    /** Set title
    */
    protected function setTitle( $title )
    {
    $this->title = $title;
    }
    /** Set data
    */
    protected function setData( $data )
    {
    // Clear any previous data
    unset( $this->data ); // Check if multiple data
    if( is_array(reset($data)) )
    {
    /** Multiple sets of data
    */
    foreach( $data as $key => $value )
    {
    // Add data values
    $this->data['values'][] = implode( ',', $value ); // Add data names
    $this->data['names'] = implode( '|', array_keys( $value ) );
    }
    /** Implode data correctly
    */
    $this->data['values'] = implode('|', $this->data['values']);
    /** Create legend
    */
    $this->legend = array_keys( $data );
    }
    else
    {
    /** Single set of data
    */
    // Add data values
    $this->data['values'] = implode( ',', $data ); // Add data names
    $this->data['names'] = implode( '|', array_keys( $data ) );
    } } /** Set legend
    */
    protected function setLegend( $legend )
    {
    $this->useLegend = $legend;
    } /** Set size
    */
    protected function setSize( $width, $height = null )
    {
    // check if width contains multiple params
    if(is_array( $width ) )
    {
    $this->size = $width;
    }
    else
    {
    // set each individually
    $this->size[] = $width;
    $this->size[] = $height;
    }
    } /** Set color
    */
    protected function setColor( $color )
    {
    $this->color = $color;
    } /** Set labels
    */
    protected function setLabelsXY( $labels )
    {
    $this->labelsXY = $labels;
    } /** Set fill
    */
    protected function setFill( $fill )
    {
    // Fill must have atleast 4 parameters
    if( count( $fill ) < 4 )
    {
    // Add remaining params
    $count = count( $fill );
    for( $i = 0; $i < $count; ++$i )
    $fill[$i] = 'b,'.$fill[$i].','.$i.','.($i+1).',0';
    }

    $this->fill = $fill;
    }
    /** Set background
    */
    protected function setBackground( $background )
    {
    $this->background = 'bg,s,'.$background;
    } /** Create img html tag
    */
    protected function img( $url, $alt = null )
    {
    return sprintf('<img src="%s" alt="%s" style="width:%spx;height:%spx;" />', $url, $alt, $this->size[0], $this->size[1]);
    }
    }