user2194507
user2194507

Reputation: 49

Adjust X Scale in highchart to display proper ratio

enter image description here

Base on image, Each X value had 20 point different and the line should display as straight line.

But Since I add 2 value which is 1025.96 and 1026.50 (as show with color background on the right table) and it still use the same scale for each number so the line graph not straight.

How can I adjust this 2 point show in the graph and make it plot proper scale? (Show straight line).

  $(document).ready(function() {


    chart = new Highcharts.Chart({
        chart: {
            renderTo: 'container2950',
            type: 'line',
            marginRight: 130,
            marginBottom: 45
        },
        title: {
            text: 'Strategy 2, Long C950',
            x: -20 //center
        },
        subtitle: {
            text: '',
            x: -20
        },
        credits: {
enabled: false
  },
        xAxis: {
  title: {
                text: 'SET50 Index ณ วันหมดอายุ'
            },
   categories:     [925,945,965,985,1005,1025,1025.96,1026.5,1045,1065,1085,1105,1125]

        },
        yAxis: {
            title: {
                text: 'Profit / Loss (Bath)'
            },
            plotLines: [{
                value: 0,
                width: 1,
                color: '#808080'
            }]
        },
        tooltip: {
            formatter: function() {
                    return '<b>'+ this.series.name +'</b><br/>'+
                    this.x +': '+ this.y +' บาท';
            }
        },
        legend: {
            layout: 'vertical',
            align: 'right',
            verticalAlign: 'top',
            x: -10,
            y: 100,
            borderWidth: 0
        },
        series: [
        {name: 'Long C950', data:     [-15300,-15300,-12300,-8300,-4300,-300,-107.99999999999,0,3700,7700,11700,15700,19700]}
        ]

    });
});

Upvotes: 0

Views: 400

Answers (1)

SteveP
SteveP

Reputation: 19103

Without any code to see, I can't be sure, but I suspect you are specifying xAxis categories. This will always equally space the x axis parameters rather than plotting them to scale.

Instead, you should specify your series data like this:

data:[ [925,-15300],[945,-15300] ]

This specifies x,y value pairs. You can also do:

data:[ {x:925,y:-15300},{x:945,y:-15300} ]

The second option allows you to set other point attributes such as colour etc.

Upvotes: 1

Related Questions