Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Creating Line Chart Using Fuelphp
  • i am fuelphp begineer.I want to create line chart in ajax.i write this code
    docs/general/controllers/rest.html
       <link href="/assets/js/nvd3/src/nv.d3.css" >
        <script src="/assets/js/nvd3/lib/d3.v3.js"></script>
        <script src="/assets/js/nvd3/nv.d3.js"></script>
        <script src="/assets/js/nvd3/src/tooltip.js"></script>
        <script src="/assets/js/nvd3/src/utils.js"></script>
        <script src="/assets/js/nvd3/src/interactiveLayer.js"></script>
        <script src="/assets/js/nvd3/src/models/legend.js"></script>
        <script src="/assets/js/nvd3/src/models/axis.js"></script>
        <script src="/assets/js/nvd3/src/models/line.js"></script>
        <script src="/assets/js/nvd3/src/models/lineChart.js"></script>
       <div id="chart"><svg></svg></div>
    <script>
    $(function() {
        $("#datepicker").datepicker();
        $('#timepicker').timepicker({'step':1, 'timeFormat': 'H:i' });
        var chart;
        var data = [{
                key: "CPU",
                color: "orange",
                values: [],
                area: true
        }];
        nv.addGraph(function() {
          chart = nv.models.lineChart();
          chart.x(function(d,i) { return d.x; });
          chart.showXAxis(true)
               .showYAxis(true)
               .rightAlignYAxis(true)
               .margin({right: 90});
          chart.xAxis
              .tickFormat(d3.format(',.0f'))
              .axisLabel("Time");
          chart.yAxis
              .axisLabel('Percentage (%)')
              .tickFormat(d3.format(',.0f'));
          d3.select('#chart svg')
              .datum(data)
            .transition().duration(500)
              .call(chart);
          chart.forceY([0,100]);
           return chart;
        });
        function refresh() {
            $.ajax({
              url: "/instance/aseMonitorServer_cpu",
              type: "post",
              dataType: "json",
              data: { arg1: 123 },
              success: function(values) {
                data[0].values = values;
                chart.update();
              }
            });
        }
        refresh();
     });
    fuel/app/class/controller
    <?php
    class Controller_Instance extends Controller_Rest {
        function post_aseMonitorServer_cpu()
        {
            $data = \DB::query("select sample_at as x, cpu_busy as y
                                  from ase_monitorServer
                                  where cpu_busy is not null
                                  and sample_at between 1382400000 and 1382430520
                                  order by sample_at
                                  limit 100")
                    ->execute()
                    ->as_array();
            return $this->response($data);
        }
    }
    i get this error.please help me!!.thank you.
    image

  • philipptempelphilipptempel
    Accepted Answer
    Guessing from your code it seems that the action "post_aseMonitorServer_cpu" is only responding to POST-requests and from the image you attached it seems you have requested the page using Firefox thus a GET-request.
    Obviously, GET =/= POST so Fuel will throw its 404-error handler. You will need to adjust either the way you are requesting the action in your browser or change the HTTP-methods the action is responding to
  • thank you .i get this data,but chart does not show yet.
    image

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion