3

I want to make a Highchart (basic line chart) which can have multiple values vs x axis.

I am trying to make a line chart with value (y axis) vs date (x axis). The problem is there can be multiple values or a perticular date. I am new to Highcharts but I went through the API and did not find a way to plot such graph which has multiple value (on y axis) vs x axis plot. I want the date to be in "06july" format.

This is my code:

 <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highcharts Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
        <script type="text/javascript">
$(function () {
        $('#g1').highcharts({
            chart:{
                polar:true,
                backgroundColor:'#E9BE51'


            } ,title: {
                text: 'Cholesterol',
                x: -20 //center
            },

            xAxis: {
               //categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug']
               //type: 'date'
            },
            yAxis: {
                title: {
                    text: 'Value(mmol/L)'
                },
                plotLines: [{
                    value: 0,
                    width: 1,
                    color: '#808080'
                }]
            },
            tooltip: {
                valueSuffix: 'in'
            },
            legend: {
                layout: 'vertical',
                align: 'right',
                verticalAlign: 'middle',
                borderWidth: 0
            },
            series: [ {
                name: 'Total',
                data: [{ name:'jan' , y:12} , {name:'jan' , y:8.2}, {name:'mar' , y:10.2} , {name:'apr' , y:14.5}]
            }/*, {
                name: 'LDL',
                data: [['jan',3.9],[ 'feb', 4.2],['mar', 5.7],['apr', 8.5] ]
            }, {
                name: 'HDL',
                data: [['jan',4.9], [ 'feb',4.0], ['mar',4.5],['apr', 6]]
            }*/]
        });
    });





        </script>
    </head>
    <body>
<script src="../../js/highcharts.js"></script>


<div class="container" id="g1" style="width: 50%; height: 50%; margin: ; "></div>



    </body>
Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99
Pulkit Tyagi
  • 61
  • 11

1 Answers1

3

To have multiple y-values for a single x-value just specify the x-value specifically when making the series. Works the same for line and datetime.

For type: 'line' you could do this (JSFiddle):

data: [[0, 7.0], [0, 10.0], 6.9, 9.5, 14.5, [3, 15.0], 18.2, 21.5, 25.2, 26.5, 23.3, [8, 10.0], 18.3, 13.9, 9.6]

For type: 'datetime' you could do this (JSFiddle):

data: [
    ...
    [Date.UTC(1971,  1, 23), 0.77],
    [Date.UTC(1971,  1, 23), 1.5],
    ...
]

And use dateTimeLabelFormats to show the dates in a specific way. See this answer for format explanation. Code could be like this (same JSFiddle above):

dateTimeLabelFormats: {
    month: '%d%B'
}
Community
  • 1
  • 1
Halvor Holsten Strand
  • 19,829
  • 17
  • 83
  • 99