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

  • Home
  • SEARCH
  • 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 6042161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:45:34+00:00 2026-05-23T06:45:34+00:00

<script type=text/javascript> var chart; $(document).ready(function() { // Define the options var options = {

  • 0
<script type="text/javascript">
    var chart;
    $(document).ready(function() {
        // Define the options
        var options = {
            chart: {
                renderTo: 'container'
            },

            title: {
                text: 'Daily visits at www.highcharts.com'
            },

            subtitle: {
                text: 'Source: Google Analytics'
            },

            xAxis: {
                type: 'datetime',
                tickInterval: 7 * 24 * 3600 * 1000, // One week
                tickWidth: 0,
                gridLineWidth: 1,
                labels: {
                    align: 'left',
                    x: 3,
                    y: -3 
                }
            },

            yAxis: [{ // Left Y axis
                title: {
                    text: null
                },
                labels: {
                    align: 'left',
                    x: 3,
                    y: 16,
                    formatter: function() {
                        return Highcharts.numberFormat(this.value, 0);
                    }
                },
                showFirstLabel: false
            }, { // right y axis
                linkedTo: 0,
                gridLineWidth: 0,
                opposite: true,
                title: {
                    text: null
                },
                labels: {
                    align: 'right',
                    x: -3,
                    y: 16,
                    formatter: function() {
                        return Highcharts.numberFormat(this.value, 0);
                    }
                },
                showFirstLabel: false
            }],

            legend: {
                align: 'left',
                verticalAlign: 'top',
                y: 20,
                floating: true,
                borderWidth: 0
            },

            tooltip: {
                shared: true,
                crosshairs: true
            },

            plotOptions: {
                series: {
                    cursor: 'pointer',
                    point: {
                        events: {
                            click: function() {
                                hs.htmlExpand(null, {
                                    pageOrigin: {
                                        x: this.pageX, 
                                        y: this.pageY
                                    },
                                    headingText: this.series.name,
                                    maincontentText: Highcharts.dateFormat('%A, %b %e, %Y', this.x) +':<br/> '+ 
                                        this.y +' visits',
                                    width: 200
                                });
                            }
                        }
                    },
                    marker: {
                        lineWidth: 1
                    }
                }
            },

            series: [{
                name: 'All visits',
                lineWidth: 4,
                marker: {
                    radius: 4
                }
            }, {
                name: 'New visitors'
            }]
        }

        // Load data asynchronously using jQuery. On success, add the data
        // to the options and initiate the chart.
        // This data is obtained by exporting a GA custom report to TSV.
        // http://api.jquery.com/jQuery.get/
        jQuery.get('analytics.tsv', null, function(tsv) {
            var lines = [],
                listen = false,
                date,

                // Set up the two data series.
                allVisits = [],
                newVisitors = [];

            try {
            // Split the data return into lines and parse them.
            tsv = tsv.split(/\n/g);
            jQuery.each(tsv, function(i, line) {
                // Listen for data lines between the Graph and Table headers.
                if (tsv[i - 3] == '# Graph') {
                    listen = true;
                } else if (line == '' || line.charAt(0) == '#') {
                    listen = false;
                }

                // All data lines start with a double quote.
                if (listen) {
                    line = line.split(/\t/);
                    date = Date.parse(line[0] +' UTC');

                    allVisits.push([
                        date, 
                        parseInt(line[1].replace(',', ''), 10)
                    ]);
                    newVisitors.push([
                        date, 
                        parseInt(line[2].replace(',', ''), 10)
                    ]);
                }
            });
            } catch (e) { alert(e.message) }
            options.series[0].data = allVisits;
            options.series[1].data = newVisitors;

            chart = new Highcharts.Chart(options);
        });
    });
</script>

Above is example code for a jQuery plugin, ‘highcharts’. I am trying to get the data from a JSON file if the JSON string is as: { name: 'allVisits', data: [1, 0, 4] }, { name: 'newVisits', data: [5, 7, 3] }.

The example file is getting the data from a ‘tsv’ file, so I am trying to get the data from the JSON file instead.

  • 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-05-23T06:45:35+00:00Added an answer on May 23, 2026 at 6:45 am

    From your short JSON example, I would say it’s invalid.

    { name: 'allVisits', data: [1, 0, 4] }, { name: 'newVisits', data: [5, 7, 3] }
    

    Should be:

     [{"name":"allVisits", "data": [1, 0, 4] }, {"name": "newVisits", "data": [5, 7, 3] }]
    

    If I recall correctly, jQuery does some JSON validation.

    Once your file is valid JSON, you can use jQuery.getJSON instead of jQuery.get.

    jQuery.getJSON( 'file.json' , function( data ){
    
       alert( data[0].name );
       // do your thang with data
    
    });
    

    Test your JSON with JSONLint

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

Sidebar

Related Questions

Here is my code <script type=text/javascript> var options = { chart: { renderTo: 'container'
Look this code: <script type = text/javascript> function mouseClick (container) { container.appendChild (document.createTextNode (Can
I have this code: <script type=text/javascript> function js() { var getJs = document.getElementById(jogo); if
Below is the code for my YWA wrapper var astr_ywascript = (document.createElement(script).type = text/javascript).src
<html> <head> <meta content=text/html; charset=utf-8 http-equiv=Content-Type> <title>Vote!</title> <script type=text/javascript> var x1 = 0; function
var script = document.createElement( 'script' ); script.type = 'text/javascript'; script.src = 'http://www.mydomain.com/bleh.php'; script.id =
<script type=text/javascript> function testing() { $.ajax({ type: POST, url: testing.php, data: call=+$(#abc).val(), success: function(msg){
<html> <head></head> <body> <script type = text/javascript> var x = 5; var y =
look at this code, <head> <meta http-equiv=Content-Type content=text/html; charset=utf-8 /> <script> function change() {
I have a jQuery script: $.ajax({ url: /scripts/secure/development/ajax.asp, type: POST, dataType: text, data: cmd=addresses,

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.