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

Message ListMessage List     Post MessagePost Message

  format the date time label on x-axis
Posted by Leo on Sep-28-2011 23:44
Here are my codes to draw two lines but the date time on the x axis didn't show the time only display the date (07/01/2008) and what I want is for example :07/01/2008 00:00:00, could I archive this?

Thank you!

const int NumberCurves = 2;
            const int CurveVerticalSpace = 30;
            const int CurveColor = 0x00aa22;

            // The data for the chart and there are 14 values
            double[] dataY1 = { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1 };

            DateTime[] dataX1 = {
                    new DateTime(2008, 7, 1, 0, 0, 0), new DateTime(2008, 7, 1, 2, 17, 2)
                    , new DateTime(2008, 7, 1, 8, 5, 30), new DateTime(2008, 7, 1, 10,
                54, 10), new DateTime(2008, 7, 1, 15, 40, 0), new DateTime(2008, 7, 1, 18,
                22, 20), new DateTime(2008, 7, 1, 22, 17, 14), new DateTime(2008, 7, 2, 2,
                55, 50), new DateTime(2008, 7, 2, 8, 17, 14), new DateTime(2008, 7, 2, 11,
                55, 50), new DateTime(2008, 7, 2, 13, 17, 14), new DateTime(2008, 7, 2, 17,
                55, 50), new DateTime(2008, 7, 2, 20, 17, 14), new DateTime(2008, 7, 3, 0, 0, 0)
                           };

            // The data for the chart and there are 12 values
            double[] dataY2 = { 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0};

            DateTime[] dataX2 = {
                    new DateTime(2008, 7, 1, 0, 0, 0), new DateTime(2008, 7, 1, 2, 17, 2)
                    , new DateTime(2008, 7, 1, 8, 5, 30), new DateTime(2008, 7, 1, 10,
                54, 10), new DateTime(2008, 7, 1, 15, 40, 0), new DateTime(2008, 7, 1, 18,
                22, 20), new DateTime(2008, 7, 1, 22, 17, 14), new DateTime(2008, 7, 2, 2,
                55, 50), new DateTime(2008, 7, 2, 8, 17, 14), new DateTime(2008, 7, 2, 11,
                55, 50), new DateTime(2008, 7, 2, 13, 17, 14), new DateTime(2008, 7, 2, 17,
                55, 50)};


            // Create a XYChart object
            // Size of the chart depends from number of shown digital curves
            XYChart chart = new XYChart(900, 70 + CurveVerticalSpace * NumberCurves, 0xdddddd);



            // line as major and minor vertical grid lines.
            PlotArea plotArea = chart.setPlotArea(50, 30, 800, NumberCurves * 30, 0xeeeeee, -1, 0x666666);
            int dashGrey = chart.dashLineColor(0x888888, Chart.DotLine);
            int dashLightGrey = chart.dashLineColor(0xcccccc, Chart.DotLine);
            plotArea.setGridColor(Chart.Transparent, dashGrey, Chart.Transparent, dashLightGrey);

            chart.yAxis().setColors(Chart.Transparent, Chart.Transparent);

            for (int i = 1; i <= NumberCurves; i++)
            {
                var dataX = i == 1 ? dataX1 : dataX2;
                var dataY = i == 1 ? dataY1 : dataY2;


                // Add step lines
                LineLayer lineLayer = chart.addLineLayer(digitalValuesLine, 0x00aa22);
                DataSet ds =lineLayer.addDataSet(zeroValuesLine, 0x00aa22);
                stepLineLayer.setXData(dataX);
                ds.setLineWidth(2);
            }

  Re: format the date time label on x-axis
Posted by Peter Kwan on Sep-29-2011 00:15
Hi Leo,

You may use Axis.setLabelFormat to control the axis label format. For example:

chart.xAxis().setLabelFormat("{value|mm/dd/yyyy\\nhh:nn:ss}");

Hope this can help.

Regards
Peter Kwan

  Re: format the date time label on x-axis
Posted by Leo on Sep-29-2011 08:44
Thanks a lot for the help.