How to change origin of yaxis of type SChartLogarithmicAxis to 0.1


#1

Hello,

Is it possible to change origin of yaxis of type SChartLogarithmicAxis having base 10 to 0.1 as shown in image below -

Origin 0.1


#2

Hello Ruchita,

I’m assuming you’re looking to get the bottom value of the y-value axis from 0 to 0.1? 

The reason it appears as 0 and not 0.1 is because as the range is so large it does not look at decimal values when calculating the default tick marks. You can however change the values to what you want using the alterTickMark delegate method. Perhaps doing something like this?

func sChart(chart: ShinobiChart!, alterTickMark tickMark: SChartTickMark!, beforeAddingToAxis axis: SChartAxis!)
    {
        if(!axis.isXAxis() && tickMark.tickLabel.text == "0")
        {
            tickMark.tickLabel.text = "0.1"
        }
    }

#3

But how to set yaxis origin to 0 of SChartLogarithmicAxis. It always starts with 1…


#4

You can get the y-axis to start from 0.1 by setting the default range to explicitly the number you want it to start from. For example:

yAxis.defaultRange = SChartRange(minimum: 0.1, andMaximum: 50000)

#5

By setting minumum value to 0.1 it does starts origin from 0 but graph is plotted as below. No bars shown between 0 - 1 also bars having value 1 are not shown…

Origin0


#6

Hi Ruchita,

To get the columns to draw to zero you can set your SChartColumnSeries’ baseline property to 0.1.

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn.


#7

Hi,

I already tried setting baseline to 0.1 but setting this property treats bars with value 0s and 1s as same showing bar till 1… See below screenshot. Also please find the code attached with data samples i am using for this particular case.

This is the data sample i am using for above chart. If you see at some initial points they have value 0 and 1… but in both case bars are plotted till 1… No way to differentiate between 0 and 1. Also tried changing anchorPoint but no luck…

-1.0~-0.9,0 -0.9~-0.8,0 -0.8~-0.7,0 -0.7~-0.6,0 -0.6~-0.5,0 -0.5~-0.4,1 -0.4~-0.3,0 -0.3~-0.2,222 -0.2~-0.1,2873 -0.1~0.0,16440 0.0~0.1,17451 0.1~0.2,9942 0.2~0.3,8204 0.3~0.4,4324 0.4~0.5,2181 0.5~0.6,634 0.6~0.7,162 0.7~0.8,17 0.8~0.9,0 0.9~1.0,0

Here is the code 

self.data = dataArray; SChartCategoryAxis *xAxis = [[SChartCategoryAxisalloc] init]; self.xAxis = xAxis; self.xAxis.style.majorTickStyle.showTicks = YES; self.xAxis.style.majorTickStyle.lineWidth = @0.5; self.xAxis.style.majorTickStyle.lineColor = [UIUtilscolorFromHexColor:LIGHT_GRAY]; SChartNumberRange *numberRange = [[SChartNumberRangealloc] initWithMinimum:[NSNumbernumberWithDouble:0.1] andMaximum:[NSNumbernumberWithDouble:max]]; SChartLogarithmicAxis *yAxis = [[SChartLogarithmicAxisalloc] initWithRange:numberRange]; yAxis.base = [NSNumbernumberWithInt:10]; yAxis.title = @"Alphas (Log Scale)"; yAxis.style.majorGridLineStyle.lineWidth = @0.5; yAxis.style.majorGridLineStyle.lineColor = [UIUtilscolorFromHexColor:LIGHT_GRAY]; yAxis.style.majorGridLineStyle.showMajorGridLines = YES; self.yAxis = yAxis; self.datasource = self; self.delegate = self; self.legend.hidden = NO; self.legend.placement = SChartLegendPlacementOutsidePlotArea; SyncingCrosshair *syncingCrosshair = [[SyncingCrosshairalloc] initWithChart:self]; syncingCrosshair.delegate = self; syncingCrosshair.interpolatePoints = NO; self.crosshair = syncingCrosshair; self.yAxis.enableGestureZooming = YES; self.yAxis.enableGesturePanning = YES; } returnself; } - (NSInteger)numberOfSeriesInSChart:(ShinobiChart *)chart { return1; } -(SChartSeries *)sChart:(ShinobiChart *)chart seriesAtIndex:(NSInteger)index { SChartColumnSeries *lineSeries = [[SChartColumnSeriesalloc] init]; lineSeries.style.areaColor = [UIUtilscolorFromHexColor:GREEN_BUTTON_BACKGROUND]; lineSeries.style.showAreaWithGradient = NO; lineSeries.title = @"Alphas"; lineSeries.baseline = @0.1; lineSeries.crosshairEnabled = YES; return lineSeries; }

#8

Hi Ruchita,

The problem you are seeing is the way we deal with zero values on a logarithmic axis as logarithmic values tend to zero.

To get the chart to render nicely with a baseline of zero you need to replace your data values equaling 0 with 0.1.

Along with the current code you already have this should produce the chart you want.

I have notified our development team of this issue.

Let me know if you have any questions.

Kind regards,
Andrew Polkinghorn.