0

I had read w3 schools tutorial and as understand I had try to write this JSON file so

  1. Is that JSON file correctly programmed?

  2. Can I run JSON file on my pc through artisteer without localhost software or server host?

{
"SitesList": 
[
{ "SiteName":"Site1" , "SiteId":100 }, 
{ "SiteName":"Site2" , "SiteId":200 },
{ "SiteName":"Site3" , "SiteId":300 }
]
}

and here is how I am trying to read this file to create chart diagram

<script type="text/javascript">
            $(function ()  
                {
   var source = new DevExpress.data.DataSource({
    load: function(loadOptions) {
        var d = $.Deferred();
        $.getJSON('C:\Users\Desktop\testfile.json').done(function(data) {
            var filteredData = DevExpress.data
              .query(data)
              .filter(loadOptions.filter)
              .toArray();
            d.resolve(filteredData);
        });
        return d.promise();
    },
    filter: ['t', '>', '6']
});

$('#chartContainer').dxChart({
    dataSource: source,
    title: 'Test Diagram',
    size: {
        height: 420
    },
    series: {
        argumentField: 'day',
        valueField: 't',
        type: 'bar'
    },
    legend: {
        visible: false
    },
    valueAxis: {
        min: 5,
        label: {
            customizeText: function() {
                return this.valueText + '&#176C';
            }
        }
    }
});

changeFilter = function(e) {
    var t = e.options&#91;e.selectedIndex&#93;.value;
    source.filter(['t', '>', t]);
    source.load();
};

var html = '<div style="margin-top: 15px">Choose a option <select onchange="changeFilter(this)"><option selected>6<\/option><option>7<\/option><option>8<\/option><option>9<\/option><option>10<\/option><option>11<\/option><option>12<\/option><\/select><\/div>';
$('#chartContainer').append(html);
}

            );
</script>
Gorpik
  • 10,940
  • 4
  • 36
  • 56
sam
  • 2,493
  • 6
  • 38
  • 73
  • use www.jsonlint.com to verify your json first. Parsing code comes after that – Rahul Gupta Feb 01 '14 at 19:03
  • really useful site thanks I was missing comma... but tell me please nca I run it though artisteer without using localhost or server host ?? is my diagram will show up ??... coz my diagram wont work – sam Feb 01 '14 at 19:08
  • Please if there is a website that help me to write javascript code to read json files like the one u provide link me to it THANKS – sam Feb 01 '14 at 19:11
  • http://stackoverflow.com/questions/16991341/js-json-parse-file-path – Rahul Gupta Feb 02 '14 at 13:21

1 Answers1

0
  1. You can check if a json is properly formatted here: http://jsonlint.com/. In this case yours isn't. Looks like you forgot a comma after the second object in the array.

  2. Accessing local files without a web server won't work on most modern browsers, but there's a way to force it. See this question for more info on that: Origin null is not allowed by Access-Control-Allow-Origin

Community
  • 1
  • 1
kbonch
  • 1