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

Message ListMessage List     Post MessagePost Message

  Three Data Sets, one with more values than another
Posted by AnthonyB on May-02-2014 00:05
How should I go about leveling these all out so my graph doesn't look like this:

http://www.tinozplace.com/multiline.png

The outdoor temperature is reported quite often, the indoor temp and AC State only change a every so often. This makes for an uneven amount of data.

What would be the best way to do this?

  Re: Three Data Sets, one with more values than another
Posted by Peter Kwan on May-02-2014 00:25
Hi AnthonyB,

You may refer to the "Uneven Data Points" sample code as a reference. Basically, when you
add a line layer, you can provide the x-coordinates of the data points using Layer.setXData.
For your case, you can create 3 line layers for the 3 lines, and use different x-coordinates
for the 3 lines. ChartDirector will plot the data points based on the x-coordinates. By
default, it will also automatically determine the x-axis scale (just like it would automatically
determine the y-axis scale), so the Axis.setLabels is not needed.

If you do not provide the x-coordinates, ChartDirector will assume the data points are align
with the axis labels one to one. This would produce the chart you currently have.

Hope this can help.

Regards
Peter Kwan

  Re: Three Data Sets, one with more values than another
Posted by AnthonyB on May-02-2014 01:39
Hello again...

I think I got all my data sets right but the graph isn't getting what I want..

http://pastebin.com/c0U8u0vt

That's the code, the url for the picture is on the original post for the updated graph.

  Re: Three Data Sets, one with more values than another
Posted by AnthonyB on May-02-2014 02:13
Ok, I think I see where this is going, sorry for the double post...

data0X = [chartTime(2007, 1, 1), chartTime(2007, 1, 2), chartTime(2007, 1, 5),
    chartTime(2007, 1, 7), chartTime(2007, 1, 10), chartTime(2007, 1, 14), chartTime(
    2007, 1, 17), chartTime(2007, 1, 18), chartTime(2007, 1, 19), chartTime(2007, 1,
    20), chartTime(2007, 1, 21)]

In there it defines the entire amount of time that the graph is going to be valid for.. In my dataset located at www.tinozplace.com/nestlog.txt you can see that has date and time..

When I define this for data0x, what is the best way to automate this?

  Re: Three Data Sets, one with more values than another
Posted by Peter Kwan on May-02-2014 02:51
Hi AnthonyB,

From your original data, you need to separate them into 6 series:

- data for AC state
- timestamps for AC state
- data for indoor temp
- timetamps for indoor temp
- data for outdoor temp
- timestamps for outdoor temp

Then you can use the 6 series as the data and x-coordinates for the 3 line layers.

Below is what I have just tried based on your original code.

Hope this can help.

Regards
Peter Kwan


import re
import urllib
from pychartdir import *

nestlog = urllib.urlopen('http://www.tinozplace.com/nestlog.txt')

#Get AC State Data
acstate = []
lengths = []
indoortemp = []
outdoortemp = []

for line in nestlog:
    if re.match(".+Home_hvac_ac_state.+", line):
        match = line.replace('Home_hvac_ac_state', '')
        match = match.replace('                                                ', ' ')
        match = match.replace('True', '100')
        match = match.replace('False', '0')
        match = match.replace('\\n', '')
        match = match.replace('\\r', '')
        match = match.replace(' ', ', ')
        match = match.split(',')
        acstate.append(match)

    if re.match(".+Home_current_temperature.+", line):
        idmatch = line.replace('Home_current_temperature', '')
        idmatch = idmatch.replace('                                          ', ' ')
        idmatch = idmatch.replace('\\n', '')
        idmatch = idmatch.replace('\\r', '')
        idmatch = idmatch.replace(' ', ', ')
        idmatch = idmatch.split(',')
        indoortemp.append(idmatch)
    if re.match(".+weather_current_temp_f.+", line):
        odmatch = line.replace('weather_current_temp_f', '')
        odmatch = odmatch.replace('                                            ', ' ')
        odmatch = odmatch.replace('\\n', '')
        odmatch = odmatch.replace('\\r', '')
        odmatch = odmatch.replace(' ', ', ')
        odmatch = odmatch.split(',')
        outdoortemp.append(odmatch)
        #print odmatch


def parseDTV(date_time_value) :
xCoor = []
data = []
for myDate, myTime, myValue in date_time_value:
yyyy, mm, dd = myDate.split('-')
hh, nn, ss = myTime.split(':')
xCoor.append(chartTime(yyyy, mm, dd, hh, nn, ss))
data.append(myValue)
return xCoor, data

ACXCoor, ACData = parseDTV(acstate)
IDXCoor, IDData = parseDTV(indoortemp)
ODXCoor, ODData = parseDTV(outdoortemp)


# Create a XYChart object of size 600 x 400 pixels. Use a vertical gradient color
# from light blue (99ccff) to white (ffffff) spanning the top 100 pixels as
# background. Set border to grey (888888). Use rounded corners. Enable soft drop
# shadow.
c = XYChart(600, 400)
c.setBackground(c.linearGradientColor(0, 0, 0, 100, 0x99ccff, 0xffffff), 0x888888)
c.setRoundedFrame()
c.setDropShadow()

# Add a title using 18 pts Times New Roman Bold Italic font. Set top margin to 16
# pixels.
c.addTitle("Nest Daata", "timesbi.ttf", 18).setMargin2(0, 0, 16, 0)

# Set the plotarea at (60, 80) and of 510 x 275 pixels in size. Use transparent
# border and dark grey (444444) dotted grid lines
plotArea = c.setPlotArea(60, 80, 510, 275, -1, -1, Transparent, c.dashLineColor(
    0x444444, 0x0101), -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 = c.addLegend(plotArea.getLeftX() + plotArea.getWidth() / 2, 45, 0,
    "arialbd.ttf", 10)
legendBox.setAlignment(TopCenter)
legendBox.setBackground(Transparent, Transparent)

# Set x-axis tick density to 75 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)
c.xAxis().setTickDensity(75)

# Set all axes to transparent
c.xAxis().setColors(Transparent)
c.yAxis().setColors(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("arialbd.ttf", 8)
c.yAxis().setLabelStyle("arialbd.ttf", 8)
c.yAxis2().setLabelStyle("arialbd.ttf", 8)

# Add axis title using 10pts Arial Bold Italic font
c.yAxis().setTitle("Backlog in USD millions", "arialbi.ttf", 10)

# Add the first data series
layer0 = c.addLineLayer2()
layer0.addDataSet(ACData, 0xff0000, "AC State").setDataSymbol(GlassSphere2Shape,
11)
layer0.setXData(ACXCoor)
layer0.setLineWidth(3)

# Add the second data series
layer1 = c.addLineLayer2()
layer1.addDataSet(IDData, 0x00ff00, "Indoor Temp").setDataSymbol(GlassSphere2Shape,
11)
layer1.setXData(IDXCoor)
layer1.setLineWidth(3)

# Add the third data series
layer2 = c.addLineLayer2()
layer2.addDataSet(ODData, 0xff6600, "Outdoor
Temp").setDataSymbol(GlassSphere2Shape, 11)
layer2.setXData(ODXCoor)
layer2.setLineWidth(3)

# Output the chart
c.makeChart("C:\\\\multiline.png")
print 'Chart Saved'

  Re: Three Data Sets, one with more values than another
Posted by AnthonyB on May-02-2014 08:00
While I was waiting for a reply, I did some more with this graph, As you'll see though, the Outdoor temperature stays the same..

I have investigated it further and it seems that I don't have any "middle" values for the one with the most updates (outdoor temp) so, it only gives the first two values.

http://pastebin.com/DsVVF5xW

I tried your function out and it worked well for a single value, but not all of the values in the variable.

I am a little lost on how to continue.

  Re: Three Data Sets, one with more values than another
Posted by AnthonyB on May-02-2014 09:47
Thanks to your function, I was able to figure it out on my own.

Thanks so much for your help.