lucasc9x
lucasc9x

Reputation: 13

Less Categories than Series on Highcharts

When I have less Categories than Series on my highcharts, the categories array autofills itselft with the index of every item from the series.

I.E:

series = [10,30,54,20,30,40,50,60,07,80,30,20]
categories = [125,250,500]

but when I plot the graph this is what I get:

series = [10,30,54,20,30,40,50,60,07,80,30,20] categories = [125,250,500,3,4,5,6,7,8,9,10,11,12]

I dont want the 4, 5, 6 ... categories to be shown, I just need the ones specified in the categories array, so each category will have more than one single point.

Heres te JSFiddle of an example that happens something like the problem that i'm having.

http://jsfiddle.net/pc4na4fk/

EDIT:
:

This is the type of graph that I need

Upvotes: 0

Views: 637

Answers (2)

lucasc9x
lucasc9x

Reputation: 13

I could solve it this way:

If I want the first category to be filled, I need to set the x property on the series object from 0.0 to 0.999.. range, and the second category 1.0 to 1.999 range and etc..

here's the JSFiddle that show's how I made it work:

 data: [[0,29.9],[0.1,39.9],[0.2,19.9],[0.3,25.9],[0.4,13.9],[1,55.9],[1.1,22.9],[1.2,23.9],[1.3,43.9],[2.1,26.9],[2.2,13.9],[2.3,19.9],[2.4,10.9]]

http://jsfiddle.net/p4fokmw3/2/

Upvotes: 1

Mike Zavarello
Mike Zavarello

Reputation: 3554

If you know how many values will be in your categories array before you define your chart options, you can set the max attribute in your x-axis to limit how many items are shown on that axis.

The value of max should be the total number of items in the categories array, minus 1. So, three items = max: 2; two items = max: 1; etc.:

    xAxis: {
        categories: ['125', '250', '500'], max: 2
    },

Here's an updated version of your fiddle with this fix: http://jsfiddle.net/brightmatrix/pc4na4fk/2/

I hope this is helpful for you!

enter image description here

Upvotes: 0

Related Questions