在html div中显示phplot图形
我正在使用phplot库来显示图形。我从他们的文档中选取了一个例子,并用一些数据进行了尝试。它在简单的php页面上运行良好 这是密码在html div中显示phplot图形,php,graph,phplot,Php,Graph,Phplot,我正在使用phplot库来显示图形。我从他们的文档中选取了一个例子,并用一些数据进行了尝试。它在简单的php页面上运行良好 这是密码 $column_names = array( 'Beef', 'Fish', 'Pork', 'Chicken', 'Butter', 'Cheese',
$column_names = array(
'Beef', 'Fish', 'Pork', 'Chicken', 'Butter',
'Cheese',
'Ice Cream');
// | | | | | | |
$data = array(
array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9),
array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.7),
array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4),
array('1970', 79.6, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8),
array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8),
);
$plot = new PHPlot(800, 500);
$plot->SetImageBorderType('plain'); // Improves presentation in the manual
$plot->SetTitle("U.S. Annual Per-Capita Consumption\n"
. "of Selected Meat and Dairy Products");
$plot->SetLegend($column_names);
# Move the legend to the lower right of the plot area:
$plot->SetLegendPixels(700, 300);
$plot->SetDataValues($data);
$plot->SetDataType('text-data-yx');
$plot->SetPlotType('stackedbars');
$plot->SetXTitle('Pounds Consumed Per Capita');
# Show data value labels:
$plot->SetXDataLabelPos('plotstack');
# Rotate data value labels to 90 degrees:
$plot->SetXDataLabelAngle(90);
# Format the data value labels with 1 decimal place:
$plot->SetXDataLabelType('data', 1);
# Specify a whole number for the X tick interval:
$plot->SetXTickIncrement(20);
# Disable the Y tick marks:
$plot->SetYTickPos('none');
$plot->DrawGraph();
$plot->SetIsInline(True);
$plot->SetOutputFile("test.png");
但当我尝试应用一些html在固定位置显示它时,我失败了。
为了在html中显示它,我在编写上述代码之后编写了以下代码
<html>
<head>
<title>PHPlot Example - Inline Image</title>
</head>
<body>
<h1>PHPlot Example - Inline Image</h1>
<div class="graph">
<img src="<?php echo $plot->EncodeImage();?>" alt="Plot Image">
</div>
</body>
</html>
PHPlot示例-内联图像
PHPlot示例-内联图像
EncodeImage();?>“alt=”打印图像“>
我得到了这样的输出
请告诉我哪里做错了。谢谢:)我通过临时保存图形图像解决了问题,然后使用该临时图像显示内部图像标记html。 这是密码
$column_names = array(
'Beef', 'Fish', 'Pork', 'Chicken', 'Butter',
'Cheese',
'Ice Cream');
// | | | | | | |
$data = array(
array('1910', 48.5, 11.2, 38.2, 11.0, 18.4, 3.9, 1.9),
array('1930', 33.7, 10.2, 41.1, 11.1, 17.6, 4.7, 9.7),
array('1950', 44.6, 11.9, 43.0, 14.3, 10.9, 7.7, 17.4),
array('1970', 79.6, 11.7, 48.1, 27.4, 5.4, 11.4, 17.8),
array('1990', 63.9, 14.9, 46.4, 42.4, 4.0, 24.6, 15.8),
);
$plot = new PHPlot(800, 500);
$plot->SetImageBorderType('plain'); // Improves presentation in the manual
$plot->SetTitle("U.S. Annual Per-Capita Consumption\n"
. "of Selected Meat and Dairy Products");
$plot->SetLegend($column_names);
# Move the legend to the lower right of the plot area:
$plot->SetLegendPixels(700, 300);
$plot->SetDataValues($data);
$plot->SetDataType('text-data-yx');
$plot->SetPlotType('stackedbars');
$plot->SetXTitle('Pounds Consumed Per Capita');
# Show data value labels:
$plot->SetXDataLabelPos('plotstack');
# Rotate data value labels to 90 degrees:
$plot->SetXDataLabelAngle(90);
# Format the data value labels with 1 decimal place:
$plot->SetXDataLabelType('data', 1);
# Specify a whole number for the X tick interval:
$plot->SetXTickIncrement(20);
# Disable the Y tick marks:
$plot->SetYTickPos('none');
$plot->DrawGraph();
$plot->SetIsInline(True);
$plot->SetOutputFile("test.png");
图像另存为test.png。现在像这样显示它
<div class="graph">
<img src="test.png" alt="Plot Image">
</div>