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

Message ListMessage List     Post MessagePost Message

  No Layer appears in Zoom Scroll Demonstration
Posted by slaniwani on Feb-10-2011 18:07
Attachments:
my Code snippet :

    c = XYChart(700, 700, brushedSilverColor(), Transparent , 2)
    c.setRoundedFrame()

    # Set the plotarea at (52, 60) and of size 520 x 192 pixels. Use white (ffffff) background.
    # Enable both horizontal and vertical grids by setting their colors to grey (cccccc). Set
    # clipping mode to clip the data lines to the plot area.
    c.setPlotArea(80, 250, 520, 350, '0xf4f4f4', -1, -1, '0x808080', '0x808080')
    c.setClipping()
    c.setDropShadow()
    # Add a top title to the chart using 15 pts Times New Roman Bold Italic font, with a light blue
    # (ccccff) background, black (000000) border, and a glass like raised effect.
    title = c.addTitle("GUI for Month Trend Line and Peak_Det", "helvetica.ttf", 15)
    title.setMargin2(0, 0, 6, 6)
    # Add a bottom title to the chart to show the date range of the axis, with a light blue (ccccff)
    # background.
    c.addLine(10, title.getHeight(), c.getWidth()-11, title.getHeight(), LineColor)
    c.addTitle2(Bottom,
        "From <*font=arialbi.ttf*>%s<*/font*> to <*font=arialbi.ttf*>%s<*/font*> (Duration " \\
        "<*font=arialbi.ttf*>%s<*/font*> days)" % (c.formatValue(viewPortStartDate,
        "{value|mmm dd, yyyy}"), c.formatValue(viewPortEndDate, "{value|mmm dd, yyyy}"), int(0.5 + (
        viewPortEndDate - viewPortStartDate) / 86400)), "ariali.ttf", 10).setBackground('0xccccff')

    # Add a legend box at the top of the plot area with 9pts Arial Bold font with flow layout.
    b = c.addLegend2(55, 33, 3, "arialbd.ttf", 9)
    b.setBackground(Transparent, Transparent)
    b.setWidth(520)

    c.yAxis().setTitle("CPU Usage(Seconds)", "arialbd.ttf", 10)
    # Set the axes width to 2 pixels
    c.xAxis().setWidth(3)
    c.xAxis().setTitle("Timestamps : Current Unix Time", "arialbd.ttf", 10)
    c.xAxis().setLabelStyle("arialbd.ttf", 8, '0x00000').setFontAngle(45)
    c.yAxis().setWidth(2)

    #================================================================================
    # Step 2 - Add data to chart
    #================================================================================

    #
    # In this example, we represent the data by lines. You may modify the code below if you want to
    # use other representations (areas, scatter plot, etc).
    #

    # Add a line layer for the lines, using a line width of 2 pixels
    layer1 = c.addAreaLayer()
    layer1.setLineWidth(1)
    layer1.setXData(chart_time)
    layer1.addDataSet(chart_value, '0x60FF0000', c.formatValue(chart_value[0], "current CPU USAGE: <*bgColor=FF6871*> {value|1} ")).setDataSymbol(CircleShape, 4, '0xFF0000')
    layer4 = c.addLineLayer2()
    layer4 = c.addScatterLayer(chart_time, chart_value, "", CircleShape, 4, '0xFF0000')
    # Now we add the 3 data series to a line layer, using the color red (ff0000), green (00cc00) and
    # blue (0000ff)
    layer2 = c.addLineLayer2()
    layer2.setXData(chart_time)
    layer2.setLineWidth(3)
    layer2.addDataSet(smooth, '0x3B26FC', "Trend Line")

    ##--------------------PEAKS------------------------------------------------------------------------------

    layer3 = c.addScatterLayer(chart_peaktime, chart_peaks,"PEAKS", StarShape(4), 15, '0xD2691E')
    layer3.setDataLabelStyle("timesbi.ttf", 10).setBackground('0xffcc66',
        Transparent, 1)
    layer5 = c.addScatterLayer(peaktime_before2, peaks_before2, "PEAK-BEFORE", StarShape(3), 15, '0xD1691E')
    layer5.setDataLabelStyle("timesbi.ttf",8).setBackground('0xff66cc',
    Transparent,1)
    layer5.moveFront()
    layer3.moveFront()




This is the Output :


In the screenshot on the bottom this should be the expected Output, its from another script.


In the Legend Boxes you see that the Data IS there. My SQL Query is working but in the zoom scroll demo, nothing appears.

please help me, whats wrong?
Screen_12 Daniel.Lammering.jpg
Screen_13 Daniel.Lammering.jpg

  Re: No Layer appears in Zoom Scroll Demonstration
Posted by slaniwani on Feb-10-2011 18:47
SOLVED it, I search the forum for "zoom scroll demonstration"

My problem was the same :

for DB in cursor.fetchall():
  myval["x"]=DB['Coltime']#.strftime("%d-%m-%Y %H:%M:%S")
  chart_time.append(chartTime(float(myval["x"])))

BUT in the image at the bottom its working with :

for DB in cursor.fetchall():
  myval["x"]=DB['Coltime']#.strftime("%d-%m-%Y %H:%M:%S")
  chart_time.append(float(myval["x"]))

Why?

Thanks
slaniwani

  Re: No Layer appears in Zoom Scroll Demonstration
Posted by Peter Kwan on Feb-11-2011 00:35
Hi salaniwani,

ChartDirector uses clock seconds elapsed since Jan 1, 0001 00:00:00. I believe the strftime returns the UNIX timestamp (physical seconds elapsed since Jan 1, 1970 00:00:00 GMT).

For example, the number 100 will be interpreted by ChartDirector to mean Jan 1, 0001 00:01:40. If it is interpreted in UNIX timestamp, it will mean Jan 1, 0001 00:01:40 GMT.

Note that if you ignore the year part, and your time zone happens to be GMT, the ChartDirector date and UNIX timestamp date are the same (they are both Jan 1 00:01:40). So sometimes even if you pass UNIX timestamps to ChartDirector, the code would still appear to work, especially if you do not display the year part. Even for cases that do not work, the difference is usually a few hours (due to difference in time zone handling between UNIX timestamp and ChartDirector chartTime).

Actually, for zooming and scrolling, it does not matter how do you encode date/time to be used for the x-coordinate. As long as the code is "consistent", the chart will display. By "consistent", I mean if the x-data are in UNIX timestamp, the x-axis scale must also be set using UNIX timestamps (not with chartTime). In this way, the chart will display, but the axis labels may not be what you expect (the year part will be incorrect, and the date/time may miss by a few hours due to time zone issues).

So for correct handling and formatting of the x-axis labels, it is suggested you always use chartTime.

Hope this can help.

Regards
Peter Kwan

  Re: No Layer appears in Zoom Scroll Demonstration
Posted by slaniwani on Feb-11-2011 16:30
Thanks for this great explanation.

My Query is looking like that :

SQL_QUERY1=("Select VALUE AS VALUE, unix_timestamp(collection_time) .......

and

for DB in cursor.fetchall():
      myval["x"]=DB['Coltime']
      chart_time.append(chartTime(float(myval["x"])))

Now its working great! :)