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

Message ListMessage List     Post MessagePost Message

  2 plotareas in an XYChart
Posted by jsumner on Jun-13-2008 22:37
Attachments:
Is there a way to put two plotareas in an xychart object? I have the plotarea for ROAA but I would also like to have a plotarea for ROAE, too. Is this possible? If so, how?
Trend in Return on Average Assets (%).png

  Re: 2 plotareas in an XYChart
Posted by Peter Kwan on Jun-14-2008 02:40
Hi jsumner,

Yes. You can combine two or more arbitrary charts together using a MultiChart object.

In your case, you have already created the first chart. You can add the first chart to the MultiChart as is.

For the second chart, it should be just the plot area with enough margins for the axis labels. Then you can add the second chart to the MultiChart, and put it right on top of the empty position in the first chart.

In VB/VBScript, it is like:

Set combinedChart = cd.MultiChart(600, 400)
combinedChart.addChart(0, 0, firstChartObject)
combinedChart.addChart(350, 80, secondChartObject)

.... output the combinedChart .....

Hope this can help.

Regards
Peter Kwan

  Re: 2 plotareas in an XYChart
Posted by jsumner on Jun-16-2008 22:50
Thanks Peter,

How would I work this into my code...see below

    ' Create an XYChart object of size 600 x 300 pixels, with a light blue (EEEEFF)
    ' background, black border, 1 pxiel 3D border effect and rounded corners
    Dim c As XYChart
    Set c = cd.XYChart(800, 390, &HE6E6E6, &H0, 1)
    Call c.setRoundedFrame
    Call c.addText(78, 30, Range("o10"), "Ite52475.ttf", 10, cd.textColor, cd.Left)
    Call c.addText(500, 30, Range("o28"), "Ite52475.ttf", 10, cd.textColor, cd.Left)

    ' Set the plotarea at (55, 58) and of size 520 x 195 pixels, with white
    ' background. Turn on both horizontal and vertical grid lines with light grey
    ' color (0xcccccc)
    Call c.setPlotArea(50, 50, 300, 260, &HFFFFFF, -1, -1, &HCCCCCC, &HCCCCCC)

    ' Add a legend box at (50, 30) (top of the chart) with horizontal layout. Use 9
    ' pts Arial Bold font. Set the background and border color to Transparent.
    Call c.addLegend(50, 360, False, "Ite52475.ttf", 9).setBackground(cd.Transparent)

    ' Add a title box to the chart using 15 pts Times Bold Italic font, on a light
    ' blue (CCCCFF) background with glass effect. white (0xffffff) on a dark red
    ' (0x800000) background, with a 1 pixel 3D border.
    'Call c.addTitle(myTitle, "Ite52475.ttf", 15 _
        ).setBackground(&HC4C4C4, &H0, cd.glassEffect())

    ' Add a title to the y axis
    If Sheet2.Cells(9, 7) = "%" Then
        Call c.yAxis().setLabelFormat("{value}%")
    Else
        Call c.yAxis().setLabelFormat("{value}")
    End If

    Call c.yAxis().setLinearScale(mylow, myhigh, myinc)

    ' Set the labels on the x axis.
    Call c.xAxis().setLabels(labels)

    ' Display 1 out of 3 labels on the x-axis.
    Call c.xAxis().setLabelStep(Sheet2.Cells(9, 2))

    ' Add a title to the x axis
    'Call c.xAxis().setTitle("Jun 12, 2006")

    ' Add a line layer to the chart
    Dim layer As LineLayer
    Set layer = c.addLineLayer2()


    ' Set the default line width to 2 pixels
    Call layer.setLineWidth(2)

    ' Add the three data sets to the line layer. For demo purpose, we use a dash line
    ' color for the last line
            Call layer.addDataSet(data0, c.dashLineColor(&HFF0000, cd.DashLine), "Bank")
            Call layer.addDataSet(data1, &H0, Sheet2.Range("B13"))
            Call layer.addDataSet(data2, &H2B30EE, Sheet2.Range("b14")).setDataSymbol(cd.DiamondSymbol, 9)



   sname = "c:\\excelpics\\" & myTitle & ".png"

   Call c.makeChart(sname)


thanks


Peter Kwan wrote:

Hi jsumner,

Yes. You can combine two or more arbitrary charts together using a MultiChart object.

In your case, you have already created the first chart. You can add the first chart to the MultiChart as is.

For the second chart, it should be just the plot area with enough margins for the axis labels. Then you can add the second chart to the MultiChart, and put it right on top of the empty position in the first chart.

In VB/VBScript, it is like:

Set combinedChart = cd.MultiChart(600, 400)
combinedChart.addChart(0, 0, firstChartObject)
combinedChart.addChart(350, 80, secondChartObject)

.... output the combinedChart .....

Hope this can help.

Regards
Peter Kwan

  Re: 2 plotareas in an XYChart
Posted by Peter Kwan on Jun-17-2008 00:50
Hi jsumner,

Your code current creates only 1 chart.

Instead of using "Call c.makeChart(sname)" to output the chart, you may:

(a) Create a second chart for the second plot area:

Dim c2 As XYChart
Set c2 = cd.XYChart(400, 360, cd.Transparent)
Call c2.setPlotArea(50, 50, 300, 260, ............)
.... add data to the second chart .......

(b) Then merge the two charts together with a multichart

Dim m As MultiChart
Set m = cd.MultiChart(800, 390, &HE6E6E6)
Call m.addChart(0, 0, c)
Call m.addChart(400, 0, c2)

(c) Output the MultiChart

Call m.makeChart(sname)

Hope this can help.

Regards
Peter Kwan

  Re: 2 plotareas in an XYChart
Posted by nuddernuby on Jul-13-2009 04:38
Hi Peter,

Could you be kind enough to provide example code for a multichart in PHP? Or tell me where I can view an example?

Many thanks

  Re: 2 plotareas in an XYChart
Posted by Peter Kwan on Jul-14-2009 00:31
Hi nuddernuby,

I have just created an example by using a MultiChart to contain the "Simple Bar Chart" and "Simple Pie Chart" sample charts.


<?php
require_once("../lib/phpchartdir.php");

# Copy from the Simple Bar Chart sample code

$data = array(85, 156, 179.5, 211, 123);
$labels = array("Mon", "Tue", "Wed", "Thu", "Fri");

$c1 = new XYChart(250, 250);
$c1->setPlotArea(30, 20, 200, 200);
$c1->addBarLayer($data);
$c1->xAxis->setLabels($labels);

# Copy from the Simple Pie Chart sample code

$data = array(25, 18, 15, 12, 8, 30, 35);
$labels = array("Labor", "Licenses", "Taxes", "Legal", "Insurance", "Facilities",
    "Production");

$c2 = new PieChart(360, 300);
$c2->setPieSize(180, 140, 100);
$c2->setData($data, $labels);

# MultiChart to contain the above two charts

$c = new MultiChart(360, 550);
$c->addChart(50, 0, $c1);
$c->addChart(0, 250, $c2);

# Output the chart
header("Content-type: image/png");
print($c->makeChart2(PNG));
?>


Hope this can help.

Regards
Peter Kwan

  Re: 2 plotareas in an XYChart
Posted by nuddernuby on Jul-14-2009 01:25
Thank you, Peter, for the quick and helpful reply.
Best regards.