PDA

View Full Version : change angle of label in chart



Tom48
11 Aug 2009, 2:10 AM
Hello,

I like to change the angle of the labels of the XAxis in a chart. But I always get a Nullpointer Exception. Am I on the wrong path?


XAxis xa = chart.getChartModel().getXAxis();
xa.getLabels().setRotation(Rotation.DIAGONAL);
chart.getChartModel().setXAxis(xa);Regards,

Tom

mtarantini
11 Aug 2009, 6:23 AM
You need to create the XAxis object before using it. The method

chart.getChartModel().getXAxis();
return null if you don't have set it in the first place.

Here a proper way to do it :



//Create the ChartModel Object
ChartModel chartModel = new ChartModel("My Title", "font-size: 23px;font-weight:bold; font-family: Verdana; text-align: center;");

//XAxis with label at 45°
XAxis xaxis = new XAxis();
List<String> axisList = new ArrayList<String>();
axisList.add("Axis A");
axisList.add("Axis B");
axisList.add("Axis C");

XLabels XLabelSerie = xaxis.new XLabels(axisList);
XLabelSerie.setRotationAngle(-45);
xaxis.setLabels(XLabelSerie);

chartModel.setXAxis(xaxis);

....

//Build your Chart Model : Take a look to the Basic Chart source example : http://extjs.com/examples-dev/explorer.html#basicchart espacially the getPieChartData method.



Hope this will help you.