jaykzoo
jaykzoo

Reputation: 3

Highstock csv date issue

Trying to use a csv file with highstocks, but there seems to be an issue with my date format. I am able to use csv files with no dates fine, highcharts without highstocks using the csv fine, and json files (dates in javascript format) fine. Can anyone please advise what I'm doing wrong?

This is sample from the csv:

Date,Value
01-05-2014,155
02-06-2014,156
03-11-2014,157

This is the code:

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

            $.get('my.csv', function (csv) {
                $('#container').highcharts('StockChart', {
                    xAxis: {
                        type: 'datetime'
                    },
                    title: {
                        text: 'Index'
                    },
                    series: [{
                        name: 'Test',
                        data: csv
                    }]
                });

            });

        });
    </script>
</head>

<body>
        <script src="../../js/highstock.js"></script>
        <script src="../../js/modules/exporting.js"></script>

        <div id="container"></div>
</body>

Upvotes: 0

Views: 1421

Answers (1)

Hibiscus
Hibiscus

Reputation: 592

In order to work with CSV files directly you'd need to use the data module.

<script src="http://code.highcharts.com/modules/data.js"></script>

and then rather then defining the series you'd pass the data to the chart as:

data: {
   csv: document.getElementById('data.csv').innerHTML 
}

Look at this for an example:

http://jsfiddle.net/9y9kzynz/1/

The way you're doing it now you'd need to load a JSON object from your ajax call, giving you something more like this:

http://jsfiddle.net/9y9kzynz/

Upvotes: 1

Related Questions