谷歌图表颜色变化


Google charts color change

我需要帮助将谷歌图表的轴颜色更改为黑色,背景颜色更改为透明。。。我在网上到处找都找不到我也尝试过css,但仍然没有成功我正在使用以下脚本:

    //Set-up the values for the Axis on the chart
    $maxWeeks = count($priceResults);
    //Set chd parameter to no value
    $chd = '';
    //Limit in my example represents weeks of the year
    $limit = 52;
    //Start to compile the prices data
    for ($row = 0; $row < $limit; $row++) {
        //Check for a value if one exists, add to $chd
        if(isset($priceResults[$row]['price']))
        {
            $chd .= $priceResults[$row]['price'];
        }
        //Check to see if row exceeds $maxWeeks
        if ($row < $maxWeeks) {
            //It doesn't, so add a comma and add the price to array $scaleValues
            $chd .= ',';
            $scaleValues[] = $priceResults[$row]['price'];
        } else if ($row >= $maxWeeks && $row < ($limit - 1)) {
            //Row exceeds, so add null value with comma
            $chd .= '_,';
        } else {
            //Row exceeds and is last required value, so just add a null value
            $chd .= '_';
        }
    }
    //Use the $scaleValues array to define my Y Axis 'buffer'
    $YScaleMax = round(max($scaleValues)) + 5;
    $YScaleMin = round(min($scaleValues)) - 5;
    //Generate the number of weeks of the year for A Axis labels
    $graphSequence = generateSequence(1, 10, "|");
    $cht = 'lc';//Set the chart type
    $chxl = '';//custom axis labels
    $chxp = '';//Axis Label Positions
    $chxr = '0,' . $YScaleMin . ',' . $YScaleMax . '|1,1,52|3,1,12|5,' . $YScaleMin . ',' . $YScaleMax . '';//Axis Range
    $chxtc = '0,5|1,5|5,5';//Axis Tick Mark Styles
    $chxt = 'y,x';//Visible Axes
    $chs = '500x200';//Chart Size in px
    $chco = '76E32C';//Series Colours
    $chds = '' . $YScaleMin . ',' . $YScaleMax . '';//Custom Scaling
    $chg = '-1,-1,1,5';//Grid lines
    $chls = '2';//line styles
    $chm = '';//Shape Markers
    //Build the URL
    $googleUrl = 'http://chart.apis.google.com/chart?';
    $rawUrl = $googleUrl . 'cht=' . $cht . '&chxl=' . $chxl . '&chxp=' . $chxp . '&chxr=' . $chxr . '&chxs=' . $chxs . '&chxtc=' . $chxtc . '&chxt=' . $chxt . '&chs=' . $chs . '&chco=' . $chco . '&chd=t:' . $chd . '&chds=' . $chds . '&chg=' . $chg . '&chls=' . $chls . '&chm=' . $chm;
    $output = $rawUrl;
    return $output;
}
/**
 * A nicer way to test arrays
 */
function displayArray($val)
{
    echo "<pre>";
    print_r($val);
    echo "</pre>";
    return;
}
/**
 * a simple numeric sequence generator. requires a min and max for the sequence, and can take an optional seperator
 */
function generateSequence($min, $max, $seperator = "")
{
    $output = '';
    for ($i = $min; $i <= $max; $i++)
    {
        $output .= $i . $seperator;
    }
    return $output;
}
$chart = generateGoogleChart();
$html = '<div id="chart">';
$html .= '<img src="' . $chart . '" />';
$html .= '</div>';
echo $html;
?>

谢谢你抽出时间。

我过去使用过Image Charts API,并实现了生成器模式来生成我的图表URL。透明背景和彩色轴在我们的应用程序中使用,方法调用提供了透明度,如下所示;

/**
 * Remove any background fill colours. The #chco parameter is used for {@link ChartType#BAR}
 * fills.
 * 
 * @return this.
 * @see https://developers.google.com/chart/image/docs/chart_params#gcharts_solid_fills
 */
public GoogleImageChartBuilder withTransparentBackgroundFill() {
 stringBuilder.append("&chf=bg,s,00000000");
 return this;
}

因此,在重新阅读与上述链接的文档时,我用chf参数进行了说明;"给我一个透明的实心背景填充"。。。也许更明智的说法是"给我一个透明的背景填充"!即

 stringBuilder.append("&chf=bg,t,00000000");

轴着色由chxs参数定义。看看这里记录的最后一个可选参数<opt_axis_color>

希望这能帮助你。请记住,API的图像图表现在已被弃用。JavaScript版本并不那么可怕:)