Android AxisTitleStyle


#1

We are using the latest version of the Android Lib of ShinobiCharts. When adding the axis to the view we want to specify the look of the axis titles. We are doing something like that:

AxisStyle as = xAxis.getStyle();
AxisTitleStyle ats = as.getTitleStyle();
ats.setTextSize(6.0f);
ats.setOrientation(Orientation.VERTICAL);
shinobiChart.addXAxis(xAxis);

But somehow this does not work. The axis title shows as exactly as before adding these lines of code. Any idea what we are doing wrong?


#2

Hi csigritz,

I can’t see anything wrong with that, apart from the lack of a chart.redrawChart(), which is generally required when you make styling changes. Here’s an equivalent snippet from our test app:

chart.getXAxis().getStyle().getTitleStyle().setOrientation(orientation);
                chart.getYAxis().getStyle().getTitleStyle().setOrientation(orientation);
                chart.redrawChart();

Best regards,

Robin Sillem


#3

Well. I am calling the redrawChart() method. Could it be, that there is a problem, that i apply the style before i have added the axis to the chart?


#4

Well. I am calling the redrawChart() method. Could it be, that there is a problem, that i apply the style before i have added the axis to the chart?


#5

Hi csigritz,

That shouldn’t be a problem. Perhaps you could send a larger snippet, showing the context you’re calling from. One thing occurs to me though: does your chart already have an X axis? V1.1 of Android charts does not support multiple axes, and addXAxis will do nothing if you already have an X axis.

Regards,

Robin Sillem


#6

We are now using the new 1.2 library, because we hoped, that this would fix the issue for us.

Here is some more code. This is within a ChartFragment. The X-Axis does not use any of the style preferences i changed. You have some idea what could be wrong here???

Thanks,

Christian

public void processReports(ArrayList<ReportRequest> reports) throws JSONException {
	ShinobiChart shinobiChart = getShinobiChart();
	
	shinobiChart.setTitle(null);
	if (reports.size() == 0) return;
	int seriesBase = reports.get(0).getDataSeriesBase();
	
	Legend legend = shinobiChart.getLegend();
    legend.setVisibility(View.VISIBLE);
    legend.setPlacement(Legend.Placement.OUTSIDE_PLOT_AREA);
    legend.setPosition(Legend.Position.TOP_CENTER);
    
    LegendStyle legendStyle = legend.getStyle();
    legendStyle.setTextSize(10.0f);
    legendStyle.setSymbolAlignment(Legend.SymbolAlignment.LEFT);
    legendStyle.setSymbolWidth(20.0f);
    legendStyle.setPadding(2.0f);
    
    //removes all series and existing axis
	cleanupChart();
	
	//Create axis
	NumberAxis yAxis = new NumberAxis();
	shinobiChart.addYAxis(yAxis);
	if (seriesBase == ReportRequest.DATA_SERIES_BASE_STRING) {
		CategoryAxis xAxis = new CategoryAxis();
		xAxis.enableGestureZooming(mUserInteractionEnabled);
		xAxis.enableGesturePanning(mUserInteractionEnabled);
		shinobiChart.addXAxis(xAxis);
		AxisStyle as = xAxis.getStyle();
		AxisTitleStyle ats = as.getTitleStyle();
		ats.setTextSize(8.0f);
		ats.setOrientation(Orientation.VERTICAL);
	} else {
		DateTimeAxis xAxis = new DateTimeAxis();
		xAxis.enableGestureZooming(mUserInteractionEnabled);
		xAxis.enableGesturePanning(mUserInteractionEnabled);
		shinobiChart.addXAxis(xAxis);
		AxisStyle as = xAxis.getStyle();
		AxisTitleStyle ats = as.getTitleStyle();
		ats.setTextSize(8.0f);
		ats.setOrientation(Orientation.VERTICAL);
	}
	
	//Add the series
	ChartType type = chartTypeFromApiString(mReport.getString("chart_type").toUpperCase());
	if (seriesBase == ReportRequest.DATA_SERIES_BASE_STRING) {
		for (ReportRequest r : reports) {
			shinobiChart.addSeries(getSeries(r, type));
		}
	} else {
		for (ReportRequest r : reports) {
			shinobiChart.addSeries(getSeries(r, type));
		}
	}
}

#7

Hi Christian

I’m still not seeing a redrawChart in there. Here’s a snippet from our test app that changes the axis title orientation in response to a UI event:

orientationPickerToolbox.setOnOrientationChangedListener(new OrientationChangedListener() {
            
            @Override
            public void onOrientationChanged(ShinobiChart chart, Title.Orientation orientation) {
                chart.getXAxis().getStyle().getTitleStyle().setOrientation(orientation);
                chart.getYAxis().getStyle().getTitleStyle().setOrientation(orientation);
                chart.redrawChart();
            }
        });

Best regards,

Robin Sillem


#8

Well. Adding the redrawChart() does not change anything.

NumberAxis yAxis = new NumberAxis();
shinobiChart.addYAxis(yAxis);
if (seriesBase == ReportRequest.DATA_SERIES_BASE_STRING) {
	CategoryAxis xAxis = new CategoryAxis();
	xAxis.enableGestureZooming(mUserInteractionEnabled);
	xAxis.enableGesturePanning(mUserInteractionEnabled);
	shinobiChart.addXAxis(xAxis);
	AxisStyle as = xAxis.getStyle();
	AxisTitleStyle ats = as.getTitleStyle();
	ats.setTextSize(8.0f);
	ats.setOrientation(Orientation.VERTICAL);
	shinobiChart.redrawChart();
} else {
	DateTimeAxis xAxis = new DateTimeAxis();
	xAxis.enableGestureZooming(mUserInteractionEnabled);
	xAxis.enableGesturePanning(mUserInteractionEnabled);
	shinobiChart.addXAxis(xAxis);
	AxisStyle as = xAxis.getStyle();
	AxisTitleStyle ats = as.getTitleStyle();
	ats.setTextSize(8.0f);
	ats.setOrientation(Orientation.VERTICAL);
	shinobiChart.redrawChart();
}

#9

Ok. Could you show us your cleanupChart method, please?


#10

No problem.

public void cleanupChart() {
	ShinobiChart shinobiChart = getShinobiChart();
	
	//remove Series
	while(shinobiChart.getSeries().size() > 0) {
		shinobiChart.removeSeries(shinobiChart.getSeries().get(0));
	}
	
	//remove Axis
	while(shinobiChart.getAllXAxes().size() > 0) {
		shinobiChart.removeXAxis(shinobiChart.getAllXAxes().get(0));
	}
	while(shinobiChart.getAllYAxes().size() > 0) {
		shinobiChart.removeYAxis(shinobiChart.getAllYAxes().get(0));
	}
}

#11

I can’t see anything wrong there. Is it just the text size and orientation that don’t  appear? i.e. you do correctly get DateTimeAxis or CategoryAxis, as appropriate? And there’s nowhere else in your app where you are setting axis styles?


#12

Everything works. It is just the orientation and the font size which does not work. I get CategoryAxis and DateTimeAxis are shown as desired. There is no other line in my code which sets axis styles.


#13

A couple more questinos, then: can you confirm with the debugger that you are actually changing the same style object as is owned by the chart, and do any other axis style settings (e.g. axis line color) work for you. Alternatively, if you have the problem sufficiently well isolated that you could send it to us at info@shinobicontrols.com I could take a look at it myself.

Best regards,

Robin Sillem