doubaran2438 2016-05-27 09:31
浏览 69

如何在php中将php数据添加到highchart js文件中

my code:

series: [{
            name: 'Brands',
            colorByPoint: true,
            <?php
            $models="SELECT * FROM purchase_info GROUP BY model_name";
            $models_querry=mysql_query($models);
            while($models_data=mysql_fetch_assoc($models_querry))
            {
            $model_name[]=$models_data['model_name'];
            }
            ?>
            data: [{
                name: ['<?php echo join($model_name, ',') ?>'],
                y: 56.33,
                drilldown: 'Hero Honda'
            }]
        }],

In my project i'm using high charts, in that how can i add php data into that, i just collect all data and saved into one variable named as $model_name[], after that i pass the array value into data, but in that it will not spitted, all data's are echoed into single one.

enter image description here

  • 写回答

1条回答 默认 最新

  • duanpo2037 2016-05-27 10:00
    关注

    Use ajax for that..see the script code

    $.ajax({
                        type: "POST",
                        url: 'ajax.php',             
                        success: function(data) {
                            a = jQuery.parseJSON(data); 
                            i=0;
                            $.each( a.total_potential_score, function( key, val ) {
                               data1[i] = parseFloat(val);
                                i++;
                            });
                            rasterize_function(data1);
                          }
                    });
    

    Ajax file look like this

    $a[0] = "1";
    $a[1] = "2";
    $a1['total_potential_score'][0] = "1";
    $a1['department_name'][0] = "aaaaa";
    $a1['total_potential_score'][1] = "3";
    $a1['department_name'][1] = "bbbbb";
    echo json_encode($a1);
    

    function for the highchart displayed here

    function rasterize_function(data1)  {
           var seriesArray = [];
           $.each( data1, function( key, val ) {
                seriesArray.push({
                name: "aaaa",
                data: [val],
                animation: false,
                dataLabels: {
                    enabled: true,
                    rotation: -90,
                    color: '#FFFFFF',
                    align: 'right',
                    x: 4,
                    y: 10,
                    style: {
                        fontSize: '13px',
                        fontFamily: 'Verdana, sans-serif'
                    }
                }
    
            });
        });
           $('#container').highcharts({
                chart: {
                    type: 'column',
                    width: 700,
                    height: 400,
                    borderWidth: 0
                },
                title: {
                    text: 'sector',
                    align: 'left'
                },
                subtitle: {
                    text: ''
                },
                xAxis: {
                    categories: ['College, Personal Development and Career Scores'],
                 },
                yAxis: {
                    min: 0,
                    title: {
                        text: 'Potential Score'
                    }
                },
                legend: {
                    layout: 'horizontal',
                    backgroundColor: '#FFFFFF',
                    verticalAlign: 'bottom',
                    x: 10,
                    y: 7,
                    floating: false,
                    shadow: true
                },
                tooltip: {
                    formatter: function() {
                        return ''+
                            this.x +': '+ this.y +' points';
                    }
                },
                plotOptions: {
                    column: {
                        animation: false,
                        pointPadding: 0.2,
                        borderWidth: 0
                    }
                },
                series:seriesArray  
    
            }); 
           }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条