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

Message ListMessage List     Post MessagePost Message

  Shifting the Day Shading
Posted by Mark Fenbers on Mar-18-2019 22:05
Notice the posted image shows a chart whose X-axis tick marks are labeled every day at 00z.  The alternating day-shading also is between 00z and the following 00z.  "z" is an abbreviation for the Universal time zone.  This is probably the most common and an intuitive choice for the default.

But my agency does things differently such that our "day" goes from noon to noon Universal time (12z to 12z).  Is there a way I can shift the alternating day-shading by 12 hours, and also shift the tick labeling by 12 hours?

I created this with v6.0.1 for Java.  Thanks for the help!


  Re: Shifting the Day Shading
Posted by Peter Kwan on Mar-19-2019 03:20
Hi Mark,

I would just use Axis.addZone in a loop to generate the alternate shading. I see in your chart, there is already a vertical pink zone between Mar 18 noon and Mar 20 noon. The same method can be used to generate the grey zones from noon to noon.

Peter Kwan

  Re: Shifting the Day Shading
Posted by Mark Fenbers on Mar-28-2019 22:44
Ok, Peter, I can do that, and bypass the built-in mechanism in CD6.  But what about the labeling?  Can I get those to appear on the noon ticks and not the midnight ticks?

  Re: Shifting the Day Shading
Posted by Peter Kwan on Mar-29-2019 16:56
Hi Mark,

If you know the start date/time and end date/time of the data, you can use your own code to generate the ticks and labels. So you can set the labels to be at noon. With this method, you no longer need to set the zones with your own code. The ChartDirector setAltBgColor will align the bands to the label positions, which are at noon.

The following is an example:

// Convert the startDate and endDate to ChartDirector chart time format (clock seconds
// elasped since epoch), as it is much easier to manipulate.
double startChartTime = Chart.CTime(startDate);
double endChartTime = Chart.CTime(endDate);

// The x-axis scale, with no labels
c.xAxis().setDateScale(startChartTime, endChartTime, Chart.NoValue);

// Use a loop to add labels, with a tick every 12 hours (= 43200 seconds)
for(double tick = Math.ceil(startChartTime / 43200) * 43200; tick<= endChartTime; tick += 43200)
    if (startTick % 86400 == 0)
        // at 00:00. use a minor tick
        c.xAxis().addLabel(startTick,  "-");
        // at noon, set the label
        c.xAxis().addLabel(startTick,  c.formatValue(startTick, "12Zn{value|w}n{value|mmm dd}"));

Hope this can help.

Peter Kwan