|
setFontAngle() not working |
Posted by Massimo Brillante on Dec-01-2014 21:03 |
|
Hi,
I am trying to set the labels angle; below the code I am using, however when i draw the chart labels have no angle at all. Can you help?
public void Draw()
{
LineLayer layer0 = null;
PlotArea plotArea = null;
if (_labels != null)
{
string[] ArrLabels = _labels.ToArray();
XYChart c = new XYChart(1000, 600);
c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888);
c.setRoundedFrame();
c.setDropShadow();
plotArea = c.setPlotArea(30, 70, 920, 450, -1, -1,
Chart.Transparent,c.dashLineColor(0x444444, 0x000101), -1);
// Add a legend box where the top-center is anchored to the horizontal center of
// the plot area at y = 45. Use horizontal layout and 10 points Arial Bold font,
// and transparent background and border.
LegendBox legendBox = c.addLegend(plotArea.getLeftX() + plotArea.getWidth() / 2,
45, false, "Verdana Bold", 10);
legendBox.setAlignment(Chart.TopCenter);
legendBox.setBackground(Chart.Transparent, Chart.Transparent);
c.xAxis().setLabels(ArrLabels).setFontAngle(90);
// c.yAxis().setAutoScale(0.1, 0.1, 0);
// Set x-axis tick density to 70 pixels and y-axis tick density to 30 pixels.
// ChartDirector auto-scaling will use this as the guidelines when putting ticks
// on the x-axis and y-axis.
c.yAxis().setTickDensity(30);//30
c.xAxis().setTickDensity(70);//70
// Set all axes to transparent
c.xAxis().setColors(Chart.Transparent);
c.yAxis().setColors(Chart.Transparent);
// Set the x-axis margins to 15 pixels, so that the horizontal grid lines can
// extend beyond the leftmost and rightmost vertical grid lines
c.xAxis().setMargin(15, 15);
// Set axis label style to 8pts Arial Bold
c.xAxis().setLabelStyle("Verdana Bold", 8);
c.yAxis().setLabelStyle("Verdana Bold", 8);
// Add the first data series
if (_data != null)
{
double[] ArrData = _data.ToArray();
layer0 = c.addLineLayer();
layer0.addDataSet(ArrData, 0xff0000, _title).setDataSymbol(Chart.GlassSphere2Shape, 11);
layer0.setLineWidth(3);
}
// Output the chart
chartControl.Image = c.makeWebImage(Chart.PNG);
chartControl.Visible = true;
}//end if we do have x0values
|
Re: setFontAngle() not working |
Posted by Massimo Brillante on Dec-01-2014 22:11 |
|
I moved this line
c.xAxis().setLabels(ArrLabels).setFontAngle(90);
just before
// Output the chart
chartControl.Image = c.makeWebImage(Chart.PNG);
and now it works |
Re: setFontAngle() not working |
Posted by Peter Kwan on Dec-01-2014 22:59 |
|
Hi Massimo,
The reason that the original code does not work is because of the line:
c.xAxis().setLabelStyle("Verdana Bold", 8);
According to the ChartDirector documentation, the setLabelStyle accepts 4 parameters -
the font name, the font size, the font color and the font angle. If you do not specify the
font color and font angle, they defaults to the default text color and to 0 degrees. So the
above line sets the font angle back to 0 degrees.
That means if you use setFontAngle, it must be put after the above setLabelStyle line, or
else the setLabeLStyle will reset the font angle to 0 degrees.
Another method is not to use setFontAngle at all, but use:
c.xAxis().setLabelStyle("Verdana Bold", 8, 0x000000, 90);
Hope this can help.
Regards
Peter Kwan |
Re: setFontAngle() not working |
Posted by Massimo Brillante on Dec-01-2014 23:45 |
|
Thanks Pater, clear as always.
I am now trying to set the Y axis which have values of integer in my database. but the
layer.addDataSet get doubles not integers any idea?
basically I do not want to display 1.0 or 2.0 but 1,2 etc.. I tried to format it in c# but of course as soon as I pass it the double array the decimals are getting back to place |
Re: setFontAngle() not working |
Posted by Massimo Brillante on Dec-02-2014 00:05 |
|
these are the test values I am passing
Dec 2010 0
Jan 2011 0
Feb 2011 0
Mar 2011 0
Apr 2011 0
May 2011 0
Jun 2011 0
Jul 2011 0
Aug 2011 0
Sep 2011 0
Oct 2011 0
Nov 2011 0
Dec 2011 0
Jan 2012 0
Feb 2012 0
Mar 2012 0
Apr 2012 0
May 2012 0
Jun 2012 0
Jul 2012 0
Aug 2012 0
Sep 2012 0
Oct 2012 0
Nov 2012 0
Dec 2012 0
Jan 2013 0
Feb 2013 0
Mar 2013 0
Apr 2013 0
May 2013 0
Jun 2013 0
Jul 2013 0
Aug 2013 0
Sep 2013 0
Oct 2013 0
Nov 2013 0
Dec 2013 0
Jan 2014 0
Feb 2014 0
Mar 2014 0
Apr 2014 0
May 2014 0
Jun 2014 0
Jul 2014 0
Aug 2014 2
Sep 2014 5
Oct 2014 5
Nov 2014 3
Dec 2014 1
but why I get a Y axis like
0.0
0.5
1.0
1.5
...
and not
0
1
2
3
4
.... |
Re: setFontAngle() not working |
Posted by Massimo Brillante on Dec-02-2014 00:16 |
|
I find a solution by calling
c.yAxis().setLinearScale(MinValue,MaxValue,1);
any better way to do it ? |
Re: setFontAngle() not working |
Posted by Peter Kwan on Dec-02-2014 22:09 |
|
Hi Massimo,
If you would like ChartDirector to auto-scale the axis, but want all labels to be integers, you
may use:
// tick position should be at multiples of 1
c.yAxis().setMinTickInc(1);
Hope this can help.
Regards
Peter Kwan |
Re: setFontAngle() not working |
Posted by Massimo on Dec-03-2014 00:42 |
|
Hi,
thanks but turns out that autoscale is more smart than I thought and with real data does actually display integers
I now have this line
c.yAxis().setAutoScale(0.1,0.1,0);
which with my poor test data displays decimals but when fired on live data which has lots of values does display integers |
Re: setFontAngle() not working |
Posted by Peter Kwan on Dec-03-2014 22:27 |
|
Hi Massimo,
In auto-scaling, the labels on the y-axis is not related to whether your data are integers or
not, but is related on the data range and how many lablels can be put on the axis. For
example, suppose your data are:
0.284, 213.2984, 111.482
None of the above values are integers, but the labels can be integers only (such as 0, 50,
100, 150, 200, 250). It is because if we use non-integer labels, a large number of labels are
required, and the axis would not have sufficient space for that much labels.
On the other hand, if your data are network utilization, and it happens to be:
0, 0, 1
The labels can be (0.0, 0.2, 0.4, 0.6, 0.8, 1, 1.2). It is because ChartDirector will use the
most detail labels possible. From ChartDirector point of view, the fact that the data values
are integers can be by chance. It does not automatically mean the data must be integers.
So ChartDirector can use non-integer labels. If you know that the data must be integers,
you can use setMinTickInc to configure ChartDirector to always use integer labels.
Hope this can help.
Regards
Peter Kwan |
Re: setFontAngle() not working |
Posted by Massimo on Dec-03-2014 22:38 |
|
Thanks Peter,
did not tried yet the c.yAxis().setMinTickInc(1); but if I do then what happens when i have data from 1 0 1.000.000 will I have 1.000.000 point on the Y axis ?
I do not want to go on the road that I ahve to assess first now much data I have and then set the c.yAxis().setMinTickInc(1); accordingly |
Re: setFontAngle() not working |
Posted by Peter Kwan on Dec-04-2014 03:05 |
|
Hi Massimo,
The setMinTickInc(1) means the tick increment to be "at least" 1. It can be more than 1 if
your data values are large. For example, if your data is from 1, 0, 1000000, and you use
setMinTickInc(1), ChartDirector will only put a few labels (eg. 0, 200000, 400000, 600000,
800000, 1000000, 1200000) on the y-axis, not 1000000 labels. So you do not need to
check if the data values are large or not.
Hope this can help.
Regards
Peter Kwan |
Re: setFontAngle() not working |
Posted by Massimo on Dec-04-2014 05:42 |
|
perfect!!!
alwasy very helpful Peter!!
Thanks |
|