dongyan1548 2019-04-28 21:54
浏览 88

没有通过jquery flot生成的图形

I try to generate a graphics where I want to display the number total orders and customer, but the graphic is not display not display. x : the date y : the total

I use jquery flot as library.

My json result (daily result):

[{"order":"18000.0000","customer":"1"},{"order":"456.0000","customer":"1"},{"order":"240.0000","customer":"1"}]

My ajax to generate the json (it's just a summary) to help you :

the sql result :

    array(2) {
  [0]=>
  array(5) {
    ["date_start"]=>
    string(19) "2019-04-20 08:17:08"
    ["date_end"]=>
    string(19) "2019-04-21 08:17:33"
    ["orders"]=>
    string(1) "2"
    ["products"]=>
    string(1) "4"
    ["sub_total"]=>
    string(10) "18456.0000"
  }
  [1]=>
  array(5) {
    ["date_start"]=>
    string(19) "2019-03-21 08:16:16"
    ["date_end"]=>
    string(19) "2019-03-21 08:16:16"
    ["orders"]=>
    string(1) "1"
    ["products"]=>
    string(1) "1"
    ["sub_total"]=>
    string(8) "240.0000"
  }
}

the loop :

  if (is_array($result_array)) {
    foreach ($result_array as $result) {
      $json[] = ['order'  => $result['sub_total'],
                'customer' => $result['orders'],
                ];
    }    

# JSON-encode the response
    $json_response = json_encode($json); //Return the JSON Array

# Return the response
    echo $json_response

Now the javascript to generate the graphic : I think in the json_response, it miss something ? But I don't see where is the problem

<script type="text/javascript"><!--
$('#range a').on('click', function(e) {
    e.preventDefault();

    $(this).parent().parent().find('li').removeClass('active');

    $(this).parent().addClass('active');

    $.ajax({
        type: 'get',
        url: '{$link}?range=' + $(this).attr('href'),
        dataType: 'json',
        success: function(json) {
            if (typeof json['order'] == 'undefined') { return false; }

            var option = {  
                shadowSize: 0,
                colors: ['#9FD5F1', '#1065D2'],
                bars: { 
                    show: true,
                    fill: true,
                    lineWidth: 1
                },
                grid: {
                    backgroundColor: '#FFFFFF',
                    hoverable: true
                },
                points: {
                    show: false
                },
                xaxis: {
                    show: true,
          ticks: json['xaxis']
                }
            }

            $.plot('#chart-sale', [json['order'], json['customer']], option);   

            $('#chart-sale').bind('plothover', function(event, pos, item) {
                $('.tooltip').remove();

                if (item) {
                    $('<div id="tooltip" class="tooltip top in"><div class="tooltip-arrow"></div><div class="tooltip-inner">' + item.datapoint[1].toFixed(2) + '</div></div>').prependTo('body');

                    $('#tooltip').css({
                        position: 'absolute',
                        left: item.pageX - ($('#tooltip').outerWidth() / 2),
                        top: item.pageY - $('#tooltip').outerHeight(),
                        pointer: 'cusror'
                    }).fadeIn('slow');  

                    $('#chart-sale').css('cursor', 'pointer');      
                } else {
                    $('#chart-sale').css('cursor', 'auto');
                }
            });
        },
/*
        error: function(xhr, ajaxOptions, thrownError) {
           alert(thrownError + "
" + xhr.statusText + "
" + xhr.responseText);
        }
*/      
    });
});

$('#range .active a').trigger('click');
//--></script>

<div id="chart-sale"></div>

Note : If I uncomment the error, I don't see anything, that's why for the moment, it's comment.

Thank you

not : if you need more information just tell me inside the comment

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
    • ¥15 YoloV5 第三方库的版本对照问题
    • ¥15 请完成下列相关问题!