We're sorry Aspose doesn't work properply without JavaScript enabled.

# Category axis in graph - change the interval unit based on number of data points in the category axis

Hi,

I have excel files with already generated graphs. I have to set the interval unit of the labels on the category axis of the graph based on some logic that I have (i,e, if I have 45 values then the interval comes every 1 unit of the category axis, if its 45-180 then every 2 units). the catergory axis for the graphs are not numbers.

From this thread I got to know how to set the interval unit. How to set the Interval unit in a chart?

But, I was looking for an easier way to see - how many data points (max possible) are there in the graph on the category axis. I was looking for a count of how may data points are there on the x axis.

getMaxDataValue does not help me in this case.

Update 7-Apr (12:27 AM Eastern) - Please see attached excel file that my code works off. Its a mockup data of a minute level sales report by day (different days go into different worksheets). "Aspose_Test_Data.xlsx"

the data for the graphs comes from the hidden worksheet (Page5).

Note: the code that I have works off the excel file itself.

requirement: (varies by data in the graph). The minute label will print at certain intervals on the x axis depending upon how many data points are there on the x axis.
e.g.
PAge1: has 30 mins worth of data (by looking at number of minutes on the x axis). So, the minute label should come at every 1 min (interval at which the label on the x axis gets printed)
Page2: has 60 mins worth of data (by looking at number of minutes on the x axis). So, the minute label should come at every 4 min.(interval at which the label on the x axis gets printed)
Page3 has 75 mins worth of data (by looking at number of minutes on the x axis). So, the minute label should come at every 11 min.(interval at which the label on the x axis gets printed)

Page 4 although has a range of 75 mins there was data returned only for the first 11 mins). So, the minute label should come at every 1 min

Question: Is there a easy way to read how many values that the graph has on the x axis. I tried the following: chart.getNSeries().get(0).getCountOfDataValues(); But, it did not seem to help.

Hi,

Thanks for the template file.

Well, if you need to get data points for a given data series, you may try to get DataPoints of the series and get its count accordingly. Please see the following code segment for your reference:
e.g
Sample code:

Workbook workbook = new Workbook(“f:\files\Aspose_Test_Data.xlsx”);
for(int i = 0; i < workbook.getWorksheets().getCount(); i++)
{

Worksheet csheet = workbook.getWorksheets().get(i);

if(csheet.isVisible() ==true)
{

Chart chart = csheet.getCharts().get(0);
//Get the first series and count of data points
SeriesCollection nseries = chart.getNSeries();
Series aseries = nseries.get(0);
ChartPointCollection datapoints = aseries.getPoints();
System.out.println(datapoints.getCount());

}

}

Hope, this helps a bit.

Thank you.