2

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

13
  • The solution that @sneha provided is a good one. What I want to share with you is that you were setting your PHP data to the name attribute of your data, when it should go into the y attribute. name is simply the name of that series, and should only have one value. y in this case would be an array of your values. Commented May 27, 2016 at 10:52
  • can u sent the solution Commented May 27, 2016 at 11:40
  • Sorry, I just looked over your screenshot again and realized I misspoke. I meant that your PHP data should be SPLIT between the name and data fields so that it would be like: { name: 'Activa 3G', data: 40 }, { name: 'CB Hornet 16GR', data: 35 }, ... Again, the answer @sneha gave you is a really good one that should solve your issue. Commented May 27, 2016 at 11:44
  • ok ok i will try, but in that ajax is used Commented May 27, 2016 at 11:45
  • please see the link highcharts.com/docs/working-with-data/data-from-a-database Commented May 27, 2016 at 11:49

1 Answer 1

2

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  

        }); 
       }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.