Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8653357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:31:20+00:00 2026-06-12T14:31:20+00:00

I’m not very familiar with JavaScript but for a project that I’m working on,

  • 0

I’m not very familiar with JavaScript but for a project that I’m working on, I need to draw a graph using some input from the db. Can you help me out with the transfer of the php values to the javascript. I just want to draw a pie chart using the data from the db.

<div id="pie" style="width:250px;height:250px;">

    <?php 
        $k=0; 
        if (isset($distrib)){
            foreach($distrib as $row){
              echo $distrib[$k]['lang'];
              echo $distrib[$k]['NumArt'];
               $k++;
            }
        }
    ?>​

    <script class="code" type="text/javascript">
        $(document).ready(function() {
            var data = [];
            var plot1 = jQuery.jqplot('pie', [data], {
                seriesDefaults: {
                    // Make this a pie chart.
                    renderer: jQuery.jqplot.PieRenderer,
                    rendererOptions: {
                        // Put data labels on the pie slices.
                        // By default, labels show the percentage of the slice.
                        showDataLabels: true
                    }
                },
                legend: {
                    show: false,
                    location: 'e'
                }
            });
        });​
    </script>

EDIT

I’m still struggling with this issue. These js charts are killing me.

So here is an additional question that will hopefully end my misery

                            if (isset($distrib)){
                                foreach($distrib as $row){
                                  $p[] = $distrib[$k]['langName'];
                                  $s[] = $distrib[$k]['lang'];
                                  $q[] = $distrib[$k]['NumArt'];
                                   $k++;
                                }}  
                            ?><?php $c = array_combine($p, $q); ?>

                        <script class="code" type="text/javascript">$(document).ready(function(){


                                    <?php echo "var s1 = [".implode($c, ",")."];" ?>
                                var plot3 = $.jqplot('pie',  [s1], {

Basically at the moment the chart is printing out numArt, but it does not print the langName which i want. Lang name stores languages in their native alphabet which means anything from arabic to Zulu. I tried using JSON with no success (i totally lack knowledge in that area). My d/encoding was messed up so I left that path.

My goal is to render a chart which has the language’s name and the amount of articles for that language.

So here is the print_r from
$p

Array ( [0] => none [1] => Catal [2] => français [3] => Malti [4] => português [5] => Kiswahili [6] => isiZulu [7] => English )

and $q
Array ( [0] => 1 [1] => 1 [2] => 1 [3] => 2 [4] => 1 [5] => 1 [6] => 1 [7] => 1 )

and the combined $c
Array ( [none] => 1 [Catal] => 1 [français] => 1 [Malti] => 2 [português] => 1 [Kiswahili] => 1 [isiZulu] => 1 [English] => 1 )

In the end I need s1 to be something along these lines

[[‘none’,1],[‘français’,1],[‘Malti’,1]]


  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T14:31:21+00:00Added an answer on June 12, 2026 at 2:31 pm
    <script type="text/javascript">
    
    var data = [ <?php echo implode(",", $array_of_values); ?> ];
    <script>
    

    Just make sure the $array_of_values is an array (PHP) containing the values you want to pass in the data variable(JS).

    UPDATE:

    $string_array = array();
    foreach( $array as $key=>$value )
    {
      $string_array[] = '[' . $key . ',' . $value . ']';
    }
    

    Then implode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a function that will clean a strings' special characters. I do NOT
I need to clean up various Word 'smart' characters in user input, including but
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.