简体   繁体   English

通过POST请求将Google图表加载到页面中

[英]Loading a Google Chart into page via POST request

So I have a page set up to use Google Chart API via POST requests. 因此,我设置了一个页面以通过POST请求使用Google Chart API。 I have multiple charts to draw each with a submit button so that a user can view any chart they want. 我有多个图表,每个图表都带有一个提交按钮,以便用户可以查看他们想要的任何图表。 So it's working where pressing the submit will load the chart, but I want to improve that. 因此,在按“提交”将加载图表的地方工作,但我想对此进行改进。

Ideally, I'd like a way (submit button or link) to submit the form with javascript, but get the result back and add the image to the page dynamically. 理想情况下,我想使用一种方式(提交按钮或链接)使用javascript提交表单,但要获取结果并动态地将图像添加到页面中。 I really don't know if it is possible to like process the form with some javascript that will pass the data to Google and give an image back without leaving the current page. 我真的不知道是否有可能喜欢使用一些JavaScript处理表单,该javascript将数据传递给Google并在不离开当前页面的情况下返回图像。 So can I? 那我可以吗

I cannot use GET (which would be easier) because I might hit the data limit. 我无法使用GET(这样会更容易),因为我可能会达到数据限制。 Also, it is way easier the way I am doing this to generate these forms into a single HTML page (instead of multiple pages and using iframes which would do what I want). 同样,将这些表单生成为单个HTML页面(而不是多个页面并使用iframe可以实现我想要的功能)的方式也更加容易。

Here is a snippet of my page with some charts. 这是我的页面的一些图表片段。 Just an example. 只是一个例子。

<tr class="chart-row">
   <td colspan="2">
      <form action="http://chart.apis.google.com/chart" method="POST" id="chartForm-idtestcasex2x32time">
      <input type="hidden" name="cht" value="lc">
      <input type="hidden" name="chs" value="800x375">
      <input type="hidden" name="chtt" value="Performance Graph for SingleFrameNotNullSurface Time">
      <input type="hidden" name="chts" value="FFFFFF,24">
      <input type="hidden" name="chco" value="000000">
      <input type="hidden" name="chls" value="2">
      <input type="hidden" name="chm" value="o,006A71,0,-1,4">
      <input type="hidden" name="chma" value="15,15,15,15">
      <input type="hidden" name="chf" value="bg,s,006A71|c,s,CCDDDD">
      <input type="hidden" name="chd" value="t:0.208,0.133">
      <input type="hidden" name="chds" value="0.12,0.22">
      <input type="hidden" name="chg" value="100,10">
      <input type="hidden" name="chxt" value="x,x,y,y">
      <input type="hidden" name="chxr" value="2,0.12,0.22,0.01">
      <input type="hidden" name="chxl" value="0:|140|143|1:|Build Number|3:|Time (ms)">
      <input type="hidden" name="chxp" value="1,50|3,50">
      <input type="hidden" name="chxs" value="0,FFFFFF|1,FFFFFF,16|2N*f5*,FFFFFF|3,FFFFFF,16">
      <input type="submit" value="Show Time Graph">
      </form>
   </td>
   <td colspan="2">
      <form action="http://chart.apis.google.com/chart" method="POST" id="chartForm-idtestcasex2x32fps">
      <input type="hidden" name="cht" value="lc">
      <input type="hidden" name="chs" value="800x375">
      <input type="hidden" name="chtt" value="Performance Graph for SingleFrameNotNullSurface Time">
      <input type="hidden" name="chts" value="FFFFFF,24">
      <input type="hidden" name="chco" value="000000">
      <input type="hidden" name="chls" value="2">
      <input type="hidden" name="chm" value="o,006A71,0,-1,4">
      <input type="hidden" name="chma" value="15,15,15,15">
      <input type="hidden" name="chf" value="bg,s,006A71|c,s,CCDDDD">
      <input type="hidden" name="chd" value="t:0,0">
      <input type="hidden" name="chds" value="-1,1">
      <input type="hidden" name="chg" value="100,25">
      <input type="hidden" name="chxt" value="x,x,y,y">
      <input type="hidden" name="chxr" value="2,-1,1,0.5">
      <input type="hidden" name="chxl" value="0:|140|143|1:|Build Number|3:|Average FPS">
      <input type="hidden" name="chxp" value="1,50|3,50">
      <input type="hidden" name="chxs" value="0,FFFFFF|1,FFFFFF,16|2N*f5*,FFFFFF|3,FFFFFF,16">
      <input type="submit" value="Show FPS Graph">
      </form>
   </td>
</tr>

You can append the parameters to the url and load it as an image with javascript. 您可以将参数附加到url,然后使用javascript将其加载为图像。

I know you said you might hit the limit with get requests, but here is an excerpt from : http://code.google.com/apis/chart/docs/making_charts.html that might help you. 我知道您说过您可能会遇到get请求的限制,但这是节录摘录: http : //code.google.com/apis/chart/docs/making_charts.html可能会对您有所帮助。

Google Chart Usage Policy Google Chart使用政策

There's no limit to the number of calls per day you can make to the Google Chart API. 您每天可以拨打Google Chart API的电话数量没有限制。 However, we reserve the right to block any use that we regard as abusive. 但是,我们保留阻止我们认为滥用的任何使用的权利。 If you think your service will make more than 250,000 API calls per day , please let us know by mailing an estimate to chart-api-notifications@google.com. 如果您认为您的服务每天将进行超过250,000次API调用 ,请通过将估算值发送到chart-api-notifications@google.com来通知我们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM