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

Message ListMessage List     Post MessagePost Message

  How to show multi-charts in one XYChart
Posted by Eva on Sep-12-2012 09:54
Attachments:
Hi ,
First of all, thank you for answering my question so that I can move on with ChartDirector.
I would like to create a XYChart with multi-charts in it, as the attached file.
Could you provide me a sample code?
BTW, i program with python in v2.4.1 with chartdirector.
Thanks a lot for your reply
temp.png

  Re: How to show multi-charts in one XYChart
Posted by Peter Kwan on Sep-13-2012 01:53
Hi Eva,

You may create multiple XYChart objects, and put them together in a MultiChart container.

Below is an example. In the code, the drawChart function is used to draw an XYChart. I have configured the chart so that its ticks are pointing inwards, and there are ticks at the 4 sides of the plot area. The drawChart is called multiple times, and a MultiChart object is used to combine the charts into a single image.


#!/usr/bin/python
from pychartdir import *

def drawChart(data, needXLabel, yTitle) :

    c = XYChart(600, 200, Transparent)
    c.setPlotArea(55, 0, 520, 150).setGridColor(0xcccccc, 0xcccccc)
    layer = c.addLineLayer(data, 0x0000ff)
    layer.setLineWidth(2)
    layer.setXData(xCoor)

    c.xAxis().setTickLength(-5)
    c.xAxis2().setTickLength(-5)
    c.xAxis2().syncAxis(c.xAxis())
    if not needXLabel :
        c.xAxis().setLabelFormat(" ")

    c.yAxis().setMargin(15, 15)
    c.yAxis2().syncAxis(c.yAxis())
    c.yAxis().setTickLength(-5)
    c.yAxis2().setTickLength(-5)
    c.yAxis2().setTitle(yTitle)
    c.yAxis2().setLabelFormat(" ")

    return c


# The data for the line chart
data0 = [42, 49, 33, 38, 51, 46, 29, 41, 44, 57, 59, 52, 37, 34, 51, 56, 56, 60, 70,
    76, 63, 67, 75, 64, 51, 77]
data1 = [50, 55, 47, 34, 42, 49, 63, 62, 73, 59, 56, 50, 64, 60, 67, 67, 58, 59, 73,
    77, 84, 82, 80, 84, 98, 82]
data2 = [36, 28, 25, 33, 38, 20, 22, 30, 25, 33, 30, 24, 28, 15, 21, 26, 46, 42, 48,
    45, 43, 52, 64, 60, 70, 56]
xCoor = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25]


m = MultiChart(600, 520)
m.addTitle("ABCD EFGH", "arialbd.ttf", 8)
m.addChart(0, 20, drawChart(data0, 0, "AAA"))
m.addChart(0, 170, drawChart(data1, 0, "BBB"))
m.addChart(0, 320, drawChart(data2, 1, "CCC"))
m.makeChart("test.png")


Hope this can help.

Regards
Peter Kwan

  Re: How to show multi-charts in one XYChart
Posted by Eva on Sep-13-2012 08:22
Hi Peter

Really thanks a lot!!!!!!

I have tried the script you provided. It worked perfectly!!!!

Really thank you ^^