/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. * *****************************************************************************/ //--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "bubbles1.h" #include "oc_color.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "OlectraChart2D_TLB" #pragma resource "*.dfm" TfrmBubbles *frmBubbles; //--------------------------------------------------------------------------- __fastcall TfrmBubbles::TfrmBubbles(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TfrmBubbles::Chart2D1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { long Series; long Point; long Distance; RegionConstants Region; Variant vValue; //See if the mouse is over a bubble Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Region = (RegionConstants)(short)vCG1.OleFunction("CoordToDataIndex", (long)X, (long)Y, oc2dFocusXY, &Series, &Point, &Distance); if ((Region != oc2dRegionInChartArea) || (Series <= 0) || (Point <= 0) || (Distance != 0)) { Series = 0; Point = 0; } UpdateFooter(Series, Point); } //--------------------------------------------------------------------------- void __fastcall TfrmBubbles::FormCreate(TObject *Sender) //This is where it all begins! { //Start with the form in the top-left corner Top = 5; Left = 5; SetupTheChart(); } //--------------------------------------------------------------------------- void __fastcall TfrmBubbles::FormResize(TObject *Sender) //Resize the Chart to the current size of the form. { Chart2D1->Width = frmBubbles->ClientWidth; Chart2D1->Height = frmBubbles->ClientHeight; } //--------------------------------------------------------------------------- void __fastcall TfrmBubbles::mnuExitClick(TObject *Sender) //End the program. { exit(0); } //--------------------------------------------------------------------------- void TfrmBubbles::SetupTheChart() //Setup how the Chart looks. { String HeaderText; Double HoldValue; //Batch all the updates to the Chart so all the changes occur at once Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Variant vCG1Data = vCG1.OlePropertyGet("Data"); vCG1.OlePropertySet("ChartType", oc2dTypeBubble); vCG1Data.OlePropertySet("NumPoints", 1, 3); vCG1Data.OlePropertySet("NumSeries", 4); //Setup the styles for the Chart Variant vStyles = vCG1.OlePropertyGet("Styles"); Variant vStyle1 = vStyles.OlePropertyGet("Item", 1); Variant vStyle3 = vStyles.OlePropertyGet("Item", 3); Variant vLine = vStyle1.OlePropertyGet("Line"); vLine.OlePropertySet("Pattern", oc2dLineNone); vLine = vStyle3.OlePropertyGet("Line"); vLine.OlePropertySet("Pattern", oc2dLineNone); Variant vSymbol = vStyle1.OlePropertyGet("Symbol"); vSymbol.OlePropertySet("Shape", oc2dShapeDot); vSymbol.OlePropertySet("Color", (int)ocColorMaroon); vSymbol = vStyle3.OlePropertyGet("Symbol"); vSymbol.OlePropertySet("Shape", oc2dShapeDot); vSymbol.OlePropertySet("Color", (int)ocColorLightSeaGreen); //Give the Chart some Data vCG1Data.OlePropertySet("Y", 1, 1, 1); vCG1Data.OlePropertySet("Y", 1, 2, 1); vCG1Data.OlePropertySet("Y", 1, 3, 1); vCG1Data.OlePropertySet("Y", 2, 1, 33.1666666666667); vCG1Data.OlePropertySet("Y", 2, 2, 10); vCG1Data.OlePropertySet("Y", 2, 3, 25.3333333333333); vCG1Data.OlePropertySet("Y", 3, 1, 2); vCG1Data.OlePropertySet("Y", 3, 2, 2); vCG1Data.OlePropertySet("Y", 3, 3, 2); vCG1Data.OlePropertySet("Y", 4, 1, 30.5); vCG1Data.OlePropertySet("Y", 4, 2, 5.83333333333333); vCG1Data.OlePropertySet("Y", 4, 3, 13.1666666666666); //Bump out the Y-Axis for a better view of the Data Variant vCA = Chart2D1->ChartArea_; Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vXAxis = vAxes.OlePropertyGet("Item", "X"); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); Variant vMin = vYAxis.OlePropertyGet("Min"); HoldValue = vMin.OlePropertyGet("Value"); vMin.OlePropertySet("Value", HoldValue - 1); Variant vMax = vYAxis.OlePropertyGet("Max"); HoldValue = vMax.OlePropertyGet("Value"); vMax.OlePropertySet("Value", HoldValue + 1); //Add some labels to help identify each group of bubbles Variant vPLabels = vCG1.OlePropertyGet("PointLabels"); vPLabels.OleFunction("Add", "General"); vPLabels.OleFunction("Add", "Western"); vPLabels.OleFunction("Add", "Eastern"); //Chnage the annotation method of the Axis so the labels added above are shown vXAxis.OlePropertySet("AnnotationMethod", oc2dAnnotatePointLabels); vXAxis.OlePropertySet("AnnotationRotationAngle", 12); //Add some Labels based on Values and then show them Variant vVLabels = vYAxis.OlePropertyGet("ValueLabels"); vVLabels.OleFunction("Add", 1, "Men"); vVLabels.OleFunction("Add", 2, "Women"); vYAxis.OlePropertySet("AnnotationMethod", oc2dAnnotateValueLabels); //Setup the Header HeaderText = "Average length of stay for patients\nwith the same type of illness\nat three different hospitals"; Variant vHeader = Chart2D1->Header; vHeader.OlePropertySet("Adjust", oc2dAdjustLeft); Variant vText = vHeader.OlePropertyGet("Text"); vText.OlePropertySet("Text", HeaderText); Variant vLocation = vHeader.OlePropertyGet("Location"); Variant vLocationLeft = vLocation.OlePropertyGet("Left"); vLocationLeft.OlePropertySet("Value", 23); Variant vBorder = vHeader.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc2dBorder3DIn); vBorder.OlePropertySet("Width", 3); Variant vInterior = vHeader.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorTan); vInterior.OlePropertySet("ForegroundColor", (int)ocColorNavyBlue); Variant vFont = vHeader.OlePropertyGet("Font"); vFont.OlePropertySet("Name", "MS Sans Serif"); vFont.OlePropertySet("Size", 10); vFont.OlePropertySet("Bold", True); vFont.OlePropertySet("Italic", True); //Make sure the Legend is visible Variant vLegend = Chart2D1->Legend_; vLegend.OlePropertySet("IsShowing", false); //Change the background color of the Chart vInterior = Chart2D1->Interior_; vInterior.OlePropertySet("BackgroundColor", (int)ocColorFirebrick); vInterior = vCA.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorTan); vInterior.OlePropertySet("ForegroundColor", (int)ocColorNavyBlue); vBorder = vCA.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc2dBorder3DIn); vBorder.OlePropertySet("Width", 5); //Setup the Footer Variant vFooter = Chart2D1->Footer; vText = vFooter.OlePropertyGet("Text"); vText.OlePropertySet("Text", "Nowhere"); vBorder = vFooter.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc2dBorder3DIn); vBorder.OlePropertySet("Width", 3); vInterior = vFooter.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorTan); vInterior.OlePropertySet("ForegroundColor", (int)ocColorNavyBlue); vFont = vFooter.OlePropertyGet("Font"); vFont.OlePropertySet("Name", "MS Sans Serif"); vFont.OlePropertySet("Size", 10); vFont.OlePropertySet("Bold", True); //Add an informational Chart Label in the Top-Right corner of the Chart Variant vCLabels = Chart2D1->ChartLabels; Variant vCLabel = vCLabels.OleFunction("Add"); vText = vCLabel.OlePropertyGet("Text"); vText.OlePropertySet("Text", "Move the mouse over a bubble to see\nlength of stay in days."); vCLabel.OlePropertySet("Name", "Label1"); vCLabel.OlePropertySet("AttachMethod", oc2dAttachCoord); Variant vAttach = vCLabel.OlePropertyGet("AttachCoord"); vAttach.OlePropertySet("X", 492); vAttach.OlePropertySet("Y", 49); vBorder = vCLabel.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc2dBorderEtchedIn); vBorder.OlePropertySet("Width", 4); vInterior = vCLabel.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorTan); vInterior.OlePropertySet("ForegroundColor", (int)ocColorDarkViolet); vFont = vCLabel.OlePropertyGet("Font"); vFont.OlePropertySet("Size", 10); //Resume regular updates to the Chart Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void TfrmBubbles::UpdateFooter(long Series, long Point) //Update the Footer to reflect the location of the mouse. { double Value; char sBuffer[80]; Variant vFooter = Chart2D1->Footer; Variant vText = vFooter.OlePropertyGet("Text"); if ((Series > 0) && (Point > 0)) { Series = ((Series - 1) * 2) + 2; //Use the logical series returned to get to the actual data Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); Variant vCG1Data = vCG1.OlePropertyGet("Data"); Value = vCG1Data.OlePropertyGet("Y", Series, Point); sprintf(sBuffer, "(%i, %i) = %4.1f", Series, Point, Value); vText.OlePropertySet("Text", sBuffer); } else { vText.OlePropertySet("Text", "Nowhere"); } } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmBubbles::mnuAboutThisDemoClick(TObject *Sender) { Application->HelpContext(91); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmBubbles::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //---------------------------------------------------------------------------