ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Behavior of Axis.SetTitle
Posted by Chris Bergin on Nov-18-2015 05:30
There are other methods that exhibit this behavior, but this is an easy example.  I make a lot of charts with ChartDirector, and to help them all have the same look and feel, I created a helper object that returns to me a chart that already has the fonts and colors set.  This way I can't make a mistake.

The helper object also tries to set the axis title properties.  So, I'd have something like this (C#):

public XYChart GetXyChart(int width, int height)
{
    /* Snip most of my code */
    chart.xAxis().setTitle("", "Segoe UI", 6, 0xACADB5);

    return chart;
}

But later, when the page that's actually rendering the chart sets a title this way:
chart.xAxis().setTitle("Widgets by Day of Week");

Then what happens is that all the fonts and colors are reset to the ChartDirector defaults.  My expectation was that by not specifying the other parameters, that they'd be left as-is, not returned to ChartDirector defaults.

So:
I understand this may be exactly as intended.  If so, is there a way to set just the axis title text without affecting the font, color, and size properties?

For now, I've just created another helper method where I pass the desired axis title in as a parameter and it sets everything in a single call, but I was curious if setTitle was supposed to behave as I'm seeing.

  Re: Behavior of Axis.SetTitle
Posted by Peter Kwan on Nov-19-2015 01:10
Hi Chris,

What you mentioned is in fact the intended behaviour. As according to the documentation,
if some parameters are not provided, they will assume the default values as mentioned in
the documention.

For your case, the common method is to use code like:

chart.xAxis().setTitle(myTitle, myAxisTitleFont, myAxisTitleFontSize, myAxisTitleFontColor);

The variables myAxisTitleFont, myAxisTitleFontSize, myAxisTitleFontColor are preset to the
values you want to use. Sometimes people put them into an object (lets called it the
"chatStyle object"), and the code becomes:

chart.xAxis().setTitle(myTitle, chartStyle.axisTitleFont, chartStyle.axisTitleFontSize,
chartStyle.axisTitleFontColor);

or it can be implemented like:

chartStyle.setAxisTitleStyle(chart.xAxis().setTitle(myTitle));

In any case, the chart object itself cannot be used to keep track of user provided default
values or styles. You would need to use a separate object to keep track of the styles.

Regards
Peter Kwan

  Re: Behavior of Axis.SetTitle
Posted by Chris Bergin on Nov-19-2015 23:11
Thank you for the confirmation.