123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133 |
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #include "ITSSkinF.h"
- #include "ITSUtilF.h"
- #include "ITSDbF.h"
- #include "AppGlobalF.h"
- #include "ITSLangTransF.h"
- #pragma hdrstop
- #include "PlugInChartF.h"
- #include "PlugInSetChartF.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma link "Chart"
- #pragma link "DBChart"
- #pragma link "Series"
- #pragma link "TeEngine"
- #pragma link "TeeProcs"
- #pragma link "cxButtons"
- #pragma link "cxCheckBox"
- #pragma link "cxContainer"
- #pragma link "cxControls"
- #pragma link "cxDropDownEdit"
- #pragma link "cxEdit"
- #pragma link "cxGraphics"
- #pragma link "cxImageComboBox"
- #pragma link "cxLabel"
- #pragma link "cxLookAndFeelPainters"
- #pragma link "cxLookAndFeels"
- #pragma link "cxMaskEdit"
- #pragma link "cxSplitter"
- #pragma link "cxTextEdit"
- #pragma link "dxSkinBlack"
- #pragma link "dxSkinBlue"
- #pragma link "dxSkinsCore"
- #pragma resource "*.dfm"
- //TPlugInChart *PlugInChart = NULL;
- //---------------------------------------------------------------------------
- __fastcall TPlugInChart::TPlugInChart(TComponent* Owner)
- : TForm(Owner)
- {
- LangTrans->Translate(this, ITSDb_GetConnection());
- ITSSkin_Load(this);
- }
- //---------------------------------------------------------------------------
- /*
- * form을 보여줄때 호출되는 event 메서드이다.
- * arguments
- * Sender : event handler 객체
- * return
- * void
- */
- void __fastcall TPlugInChart::FormShow(TObject *Sender)
- {
- // form 초기화
- FormInit();
- DbChart->SetFocus();
- DbChart->Title->Visible = false;
- //DbChart->Title->Text->Strings[0] = "";
- DbChart->Title->Caption = "";
- //Caption = m_sCaption;
- }
- //---------------------------------------------------------------------------
- /*
- * form 초기화
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::FormInit()
- {
- CbChartKind->ItemIndex = 0;
- //LstLegend->Style = Stdctrls::lbOwnerDrawFixed;
- DbChart->View3D = false;
- //ClearChart();
- //LstLegend->Refresh();
- }
- //---------------------------------------------------------------------------
- /*
- * Form을 닫을때 호출되는 event 메서드
- * arguments
- * Sender : event handler 객체
- * Action : TCloseAction 객체
- * return
- * void
- */
- void __fastcall TPlugInChart::FormClose(TObject *Sender, TCloseAction &Action)
- {
- //상속한 PlugIn 폼에서는 CommClose() 함수를 override 하여 사용하자.
- CommClose();
- Action = caFree;
- }
- //---------------------------------------------------------------------------
- /*
- * 닫기버튼 이나 x버튼 클릭시 공통으로 처리하는 로직이들어간다..
- * Form과 DataModule class를 delete시킨다.
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::CommClose()
- {
- try
- {
- Clear();
- }
- catch(...)
- {
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 공통으로 처리되지 않는 스킨을 변경한다.
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::LoadLocalSkin()
- {
- /*
- * 스킨 변경
- */
- //FrmResource->LoadSkinTitle(this, NULL, NULL, NULL);
- //FrmResource->LoadSkinButton(BtnChkAll, BtnReverse, BtnProperty, NULL, NULL, NULL, NULL, NULL);
- #if 0
- switch (SkinType)
- {
- case 1:
- Splitter->Color = (TColor)0x00FDE8D7;
- break;
- case 2:
- Splitter->Color = (TColor)0x003B69F0;
- break;
- case 3:
- Splitter->Color = (TColor)0x00BAA181;
- break;
- case 4:
- Splitter->Color = (TColor)0x00F8C6A4;
- break;
- case 5:
- Splitter->Color = (TColor)0x00A3D8C9;
- break;
- case 6:
- Splitter->Color = (TColor)0x004A189C;
- break;
- default:
- Splitter->Color = (TColor)0x003B69F0;//0x00F5F5F5;
- break;
- }
- #endif
- }
- //---------------------------------------------------------------------------
- /*
- * Legend check all button click event
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::BtnChkAllClick(TObject *Sender)
- {
- // Check all
- LstLegend->Items->BeginUpdate();
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- LstLegend->Checked[ii] = true;
- }
- LstLegend->Items->EndUpdate();
- BtnApplyClick(NULL);
- }
- //---------------------------------------------------------------------------
- /*
- * Legend Reverse button click event
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::BtnReverseClick(TObject *Sender)
- {
- // Reverse check
- LstLegend->Items->BeginUpdate();
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- LstLegend->Checked[ii] = !LstLegend->Checked[ii];
- }
- LstLegend->Items->EndUpdate();
- BtnApplyClick(NULL);
- }
- //---------------------------------------------------------------------------
- /*
- * Legend Property button click event
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::BtnPropertyClick(TObject *Sender)
- {
- // Legend property setting
- LstLegendDblClick(NULL);
- }
- //---------------------------------------------------------------------------
- /*
- * Chart property apply
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::BtnApplyClick(TObject *Sender)
- {
- // Apply
- int nRes = 0;
- LstLegend->Items->BeginUpdate();
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- nRes += SetActive(ii);
- }
- if (nRes)
- {
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- }
- LstLegend->Items->EndUpdate();
- }
- //---------------------------------------------------------------------------
- /*
- * Chart 3d on/off
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::Chk3DClick(TObject *Sender)
- {
- DbChart->Locked = true;
- try
- {
- // DbChart->Aspect->Orthogonal = false;
- DbChart->View3D = Chk3D->Checked;
- }
- __finally
- {
- DbChart->Locked = false;
- DbChart->Update();
- }
- BtnApplyClick(NULL);
- }
- //---------------------------------------------------------------------------
- /*
- * Chart Label value display on/off
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::ChkDispValueClick(TObject *Sender)
- {
- try
- {
- DbChart->Locked = true;
- int nSeries = DbChart->SeriesCount();
- for (int ii = 0; ii < nSeries; ii++)
- {
- DbChart->Series[ii]->Marks->Style = smsValue;
- DbChart->Series[ii]->Marks->Visible = !DbChart->Series[ii]->Marks->Visible;
- }
- }
- __finally
- {
- DbChart->Locked = false;
- }
- #if 0
- // Label value display on/off
- SeriesItem* pSrsItem;
- TChartSeries *pSeries;
- //DbChart->Series->BeginUpdate();
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[ii];
- if (pSrsItem == NULL) continue;
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- if (pSeries == NULL) continue;
- pSeries->Marks->Style = smsValue;
- pSeries->Marks->Visible = ChkDispValue->Checked;
- }
- //DbChart->Series->EndUpdate();
- #endif
- }
- //---------------------------------------------------------------------------
- /*
- * Chart kind select
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::CbChartKindPropertiesEditValueChanged(TObject *Sender)
- {
- //ChangeSeries(DbChart, (SeriesType)CbChartKind->ItemIndex, DbChart->SeriesCount());
- SeriesItem *pSrsItem;
- TChartSeries *pSeries;
- SeriesType SrsTypeNew;
- SrsTypeNew = (SeriesType)CbChartKind->ItemIndex;
- try
- {
- DbChart->Locked = true;
- LstLegend->Items->BeginUpdate();
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[ii];
- if (pSrsItem == NULL) continue;
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- if (pSeries == NULL) continue;
- ChangeSeriesItem(ii, SrsTypeNew);
- }
- }
- __finally
- {
- LstLegend->Items->EndUpdate();
- DbChart->Locked = false;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * DBChart 의 모양을 변경한다.
- * arguments
- * pDBChart - DBChart 컴포넌트
- * pSeriesIndex - 챠트유형 콤보에서 선택한 유형 index
- * return
- * void
- */
- void __fastcall TPlugInChart::ChangeSeriesItem(int nIdx, SeriesType ToSrsType)
- {
- SeriesItem* pSrsItem;
- TChartSeries *pSeries;
- TMetaClass* NewType;
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[nIdx];
- if (pSrsItem == NULL) return;
- if (pSrsItem->SrsType == ToSrsType) return;
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- switch (ToSrsType)
- {
- case ctpLine: NewType = __classid(TLineSeries); break;
- case ctpBar: NewType = __classid(TBarSeries); break;
- case ctpHorizontal_Bar: NewType = __classid(THorizBarSeries); break;
- case ctpArea: NewType = __classid(TAreaSeries); break;
- case ctpPoint: NewType = __classid(TPointSeries); break;
- case ctpPie: NewType = __classid(TPieSeries); break;
- case ctpFast_Line: NewType = __classid(TFastLineSeries); break;
- case ctpHorizontal_Line: NewType = __classid(THorizLineSeries); break;
- case ctpHorizontal_Area: NewType = __classid(THorizAreaSeries); break;
- case ctpShape: NewType = __classid(TChartShape); break;
- case ctpGantt: NewType = __classid(TGanttSeries); break;
- case ctpArrow: NewType = __classid(TArrowSeries); break;
- case ctpBubble: NewType = __classid(TBubbleSeries); break;
- default : return;
- }
- ChangeSeriesType(pSeries, NewType);
- pSrsItem->ChartSeries = (void*)pSeries;
- pSrsItem->SrsType = ToSrsType;
- if (ToSrsType == ctpLine)
- {
- ((TLineSeries*)pSeries)->Pointer->Style = psRectangle;
- ((TLineSeries*)pSeries)->Pointer->VertSize = 4;
- ((TLineSeries*)pSeries)->Pointer->Visible = true;
- }
- else if(ToSrsType == ctpPie)
- {
- ((TPieSeries*)pSeries)->Marks->Style = smsValue;
- ((TPieSeries*)pSeries)->Circled = true;
- //((TPieSeries*)pSeries)->Marks->Visible = ChkDispValue->Checked;
- }
- pSeries->Marks->Style = smsValue;
- pSeries->Marks->Visible = ChkDispValue->Checked;
- }
- //---------------------------------------------------------------------------
- void __fastcall TPlugInChart::ChangeSeries(TDBChart *pDBChart, SeriesType nSeriesTp, int nSeriesCount)
- {
- TChartSeries *pChartSeries;
- if (pDBChart == NULL) return;
- for (int ii = 0; ii < nSeriesCount; ii++)
- {
- try
- {
- pChartSeries = pDBChart->Series[ii];
- switch(nSeriesTp)
- {
- case ctpLine: ChangeSeriesType(pChartSeries, __classid(TLineSeries)); break;
- case ctpBar: ChangeSeriesType(pChartSeries, __classid(TBarSeries)); break;
- case ctpHorizontal_Bar: ChangeSeriesType(pChartSeries, __classid(THorizBarSeries)); break;
- case ctpArea: ChangeSeriesType(pChartSeries, __classid(TAreaSeries)); break;
- case ctpPoint: ChangeSeriesType(pChartSeries, __classid(TPointSeries)); break;
- case ctpPie: ChangeSeriesType(pChartSeries, __classid(TPieSeries)); break;
- case ctpFast_Line: ChangeSeriesType(pChartSeries, __classid(TFastLineSeries)); break;
- case ctpHorizontal_Line: ChangeSeriesType(pChartSeries, __classid(THorizLineSeries)); break;
- case ctpHorizontal_Area: ChangeSeriesType(pChartSeries, __classid(THorizAreaSeries)); break;
- case ctpShape: ChangeSeriesType(pChartSeries, __classid(TChartShape)); break;
- case ctpGantt: ChangeSeriesType(pChartSeries, __classid(TGanttSeries)); break;
- case ctpArrow: ChangeSeriesType(pChartSeries, __classid(TArrowSeries)); break;
- case ctpBubble: ChangeSeriesType(pChartSeries, __classid(TBubbleSeries)); break;
- }
- }
- catch(...)
- {
- }
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 조회 전 챠트를 Clear 한다.
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::ClearChart()
- {
- try
- {
- for (int ii = 0; ii < DbChart->SeriesCount(); ii++)
- {
- DbChart->Series[ii]->Clear();
- }
- }
- catch(...)
- {
- }
- }
- //---------------------------------------------------------------------------
- /*
- * Check on/off legend
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::LstLegendClickCheck(TObject *Sender)
- {
- // Check on/off legend
- int nIdx = LstLegend->ItemIndex;
- LstLegend->Items->BeginUpdate();
- if (SetActive(nIdx))
- {
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- }
- LstLegend->Items->EndUpdate();
- }
- //---------------------------------------------------------------------------
- /*
- * double legend list
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::LstLegendDblClick(TObject *Sender)
- {
- // double legend list
- SeriesItem *pSrsItem;
- TChartSeries *pSeries;
- SeriesType SrsTypeNew;
- int idx;
- String sMsgTitle, sMsgString;
- idx = LstLegend->ItemIndex;
- if(idx < 0)
- {
- sMsgString = lblSel->Caption;//"아이템을 선택하세요.";
- MessageDlg(sMsgString.c_str(), mtInformation, TMsgDlgButtons() << mbOK, NULL);
- return;
- }
- pSrsItem = (SeriesItem *)LstLegend->Items->Objects[idx];
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- try
- {
- TPlugInSetChart *PlugInSetChart = new TPlugInSetChart(Parent);
- PlugInSetChart->EdtItemNm->Text = pSeries->Title;
- PlugInSetChart->ChkVisible->Checked = pSeries->Active;
- PlugInSetChart->PnlItemColor->Color = pSeries->SeriesColor;
- PlugInSetChart->m_nSrsType = pSrsItem->SrsType;
- if (PlugInSetChart->ShowModal() == mrOk)
- {
- Application->ProcessMessages();
- pSeries->Active = PlugInSetChart->ChkVisible->Checked;
- LstLegend->Checked[idx] = pSeries->Active;
- pSeries->SeriesColor = PlugInSetChart->PnlItemColor->Color;
- SrsTypeNew = (SeriesType)PlugInSetChart->m_nSrsType;
- if (pSrsItem->SrsType != SrsTypeNew)
- {
- ChangeSeriesItem(idx, SrsTypeNew);
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- }
- LstLegend->Repaint();
- }
- delete PlugInSetChart;
- PlugInSetChart = NULL;
- }
- catch(...)
- {
- }
- #if 0
- pSrsItem = (SeriesItem*)lstItems->Items->Objects[idx];
- FrmSTC_Grph_Prop->lblSrsTitle->Caption = pSeries->Title;
- FrmSTC_Grph_Prop->chxSrsActive->Checked = pSeries->Active;
- FrmSTC_Grph_Prop->lblSrsColor->Color = pSeries->SeriesColor;
- FrmSTC_Grph_Prop->SetSrsTypeBtn(pSrsItem->SrsType);
- if(FrmSTC_Grph_Prop->ShowModal() == mrOk)
- {
- Application->ProcessMessages();
- pSeries->Active = FrmSTC_Grph_Prop->chxSrsActive->Checked;
- lstItems->Checked[idx] = pSeries->Active;
- pSeries->SeriesColor = FrmSTC_Grph_Prop->lblSrsColor->Color;
- SrsTypeNew = FrmSTC_Grph_Prop->FSrsType;
- if(pSrsItem->SrsType != SrsTypeNew)
- {
- ChangeSeriesItem(idx, SrsTypeNew);
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- }
- lstItems->Repaint();
- }
- delete FrmSTC_Grph_Prop;
- FrmSTC_Grph_Prop = NULL;
- #endif
- }
- //---------------------------------------------------------------------------
- /*
- * Draw legend items
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::LstLegendDrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
- {
- TCanvas* pCvs = LstLegend->Canvas;
- int Offset = 2, iBarWidth = 12;
- TColor brColor;
- TRect rct;
- SeriesType SrsType;
- brColor = pCvs->Brush->Color;
- pCvs->Pen->Color = brColor;
- pCvs->Rectangle(Rect);
- // Chart Type Rect
- pCvs->Brush->Color = clWhite;
- rct = Rect;
- rct.Top = Rect.Top + 1;
- rct.Right = Rect.Left + iBarWidth;
- rct.Bottom = Rect.Bottom - 1;
- pCvs->Rectangle(rct);
- DrawSeriesType(GetSeriesType(Index), pCvs, rct);
- // Chart Color Rect
- Rect.Left += iBarWidth + Offset;
- pCvs->Pen->Color = TColor(0x00646464);
- pCvs->Brush->Color = GetSeriesColor(Index);
- pCvs->Rectangle(Rect.Left, Rect.Top + 1,
- Rect.Left + iBarWidth, Rect.Bottom - 1);
- // Chart Label
- pCvs->Brush->Color = brColor;
- Rect.Left += iBarWidth + Offset;
- pCvs->TextOut(Rect.Left, Rect.Top, LstLegend->Items->Strings[Index]);
- }
- //---------------------------------------------------------------------------
- /*
- * Get Chart type
- *
- * arguments
- * return
- * void
- */
- SeriesType __fastcall TPlugInChart::GetSeriesType(int nIdx)
- {
- SeriesItem* pSrsItem;
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[nIdx];
- return pSrsItem->SrsType;
- }
- //---------------------------------------------------------------------------
- /*
- * Get Chart serice color
- *
- * arguments
- * return
- * void
- */
- TColor __fastcall TPlugInChart::GetSeriesColor(int nIdx)
- {
- SeriesItem *pSrsItem;
- TChartSeries *pSeries;
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[nIdx];
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- return pSeries->SeriesColor;
- }
- //---------------------------------------------------------------------------
- /*
- * Draw chart type on legend list
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::DrawSeriesType(SeriesType SrsType, TCanvas* pCvs, TRect Rct)
- {
- int x, y;
- x = Rct.Left, y = Rct.Bottom;
- pCvs->Pen->Color = clBlack;
- switch(SrsType)
- {
- /*
- ctpLine = 0,
- ctpBar,
- ctpHorizontal_Bar,
- ctpArea,
- ctpPoint,
- ctpFastLine,
- */
- case ctpLine : y -= (Rct.Bottom - Rct.Top) / 3;
- pCvs->MoveTo(x, y);
- x += (Rct.Right - Rct.Left) / 3;
- y -= (Rct.Bottom - Rct.Top) / 2;
- pCvs->LineTo(x, y);
- x += (Rct.Right - Rct.Left) / 4;
- y += (Rct.Bottom - Rct.Top) / 2;
- pCvs->LineTo(x, y);
- x = Rct.Right;
- y -= (Rct.Bottom - Rct.Top) / 2;
- pCvs->LineTo(x, y);
- break;
- case ctpBar : Rct.Top += 8;
- Rct.Left += 3; Rct.Right = Rct.Left + 1;
- pCvs->Rectangle(Rct);
- Rct.Top -= 2;
- Rct.Left = Rct.Right + 2; Rct.Right = Rct.Left + 1;
- pCvs->Rectangle(Rct);
- Rct.Top -= 4;
- Rct.Left = Rct.Right + 2; Rct.Right = Rct.Left + 1;
- pCvs->Rectangle(Rct);
- break;
- case ctpArea : Rct.Top += 1; Rct.Bottom -= 1;
- pCvs->Ellipse(Rct);
- pCvs->Pie(Rct.Left, Rct.Top, Rct.Right, Rct.Bottom,
- Rct.Left, Rct.Top, Rct.Right, Rct.Top + 3);
- pCvs->Pie(Rct.Left, Rct.Top, Rct.Right, Rct.Bottom,
- Rct.Left, Rct.Top, Rct.Left + 4, Rct.Bottom);
- break;
- case ctpPoint: Rct.Top += 8;
- Rct.Left += 3; Rct.Right = Rct.Left + 2;
- pCvs->Rectangle(Rct);
- //Rct.Top -= 5;
- Rct.Left = Rct.Right + 2; Rct.Right = Rct.Left + 2;
- pCvs->Rectangle(Rct);
- break;
- default : break;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * Active show/hide legend
- *
- * arguments
- * return
- * void
- */
- bool __fastcall TPlugInChart::SetActive(int nIdx)
- {
- SeriesItem* pSrsItem;
- TChartSeries *pSeries;
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[nIdx];
- if (pSrsItem == NULL) return false;
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- if (pSeries == NULL) return false;
- if (pSeries->Active != LstLegend->Checked[nIdx])
- {
- pSeries->Active = LstLegend->Checked[nIdx];
- return true;
- }
- return false;
- }
- //---------------------------------------------------------------------------
- /*
- * Get active chart Y axis value
- *
- * arguments
- * return
- * void
- */
- double __fastcall TPlugInChart::GetActiveMaxY(void)
- {
- SeriesItem *pSrsItem;
- TChartSeries *pSeries;
- double dMaxY = 0.0;
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- pSrsItem = (SeriesItem*)LstLegend->Items->Objects[ii];
- if (pSrsItem == NULL) continue;
- pSeries = (TChartSeries*)pSrsItem->ChartSeries;
- if (pSeries == NULL) continue;
- if (pSeries->Active == false) continue;
- if(dMaxY < pSeries->YValues->MaxValue)
- dMaxY = pSeries->YValues->MaxValue;
- }
- double calMaxY = dMaxY + (dMaxY / 20.);
- return calMaxY;// > DbChart->LeftAxis->Minimum ? calMaxY : DbChart->LeftAxis->Minimum;
- }
- //---------------------------------------------------------------------------
- /*
- * 차트 정보 설정
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::SetChartInfo(String sTitle, String sAxisX, String sAxisY)
- {
- DbChart->Title->Visible = false;
- DbChart->BottomAxis->Title->Visible = false;
- DbChart->LeftAxis->Title->Visible = false;
- if (sTitle != "")
- {
- DbChart->Title->Caption = sTitle;
- DbChart->Title->Visible = true;
- }
- if (sAxisY != "")
- {
- DbChart->BottomAxis->Title->Caption = sAxisX;
- DbChart->BottomAxis->LabelStyle = talText;
- DbChart->BottomAxis->LabelsAngle = 0;
- DbChart->BottomAxis->Title->Visible = true;
- }
- if (sAxisX != "")
- {
- DbChart->LeftAxis->Title->Caption = sAxisY;
- DbChart->LeftAxis->Title->Visible = true;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 차트 그리기전에 반드시 호출
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::BeginDraw(String sTitle/*=""*/, String sAxisX/*=""*/, String sAxisY/*=""*/)
- {
- ClearData();
- SetChartInfo(sTitle, sAxisX, sAxisY);
- }
- //---------------------------------------------------------------------------
- /*
- * 메모리를 해제한다.
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::Clear()
- {
- ClearData();
- }
- //---------------------------------------------------------------------------
- /*
- * 메모리를 해제한다.
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::ClearData()
- {
- try
- {
- LstLegend->Items->BeginUpdate();
- try
- {
- for (int ii = 0; ii < LstLegend->Count; ii++)
- {
- SeriesItem *pSrsItem = (SeriesItem *)LstLegend->Items->Objects[ii];
- if (pSrsItem == NULL) continue;
- delete pSrsItem;
- }
- LstLegend->Items->Clear();
- ClearChart();
- DbChart->FreeAllSeries();
- }
- catch(...)
- {
- }
- }
- __finally
- {
- LstLegend->Items->EndUpdate();
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 해당되지 않는 컬럼을 클리어한다.
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::DrawChart1(TcxGridDBTableView *TvList, int nAxisY, int nStColIdx, int nTotColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TClientDataSet *pCDS = NULL;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- pCDS = (TClientDataSet *)TvList->DataController->DataSource->DataSet;
- if (pCDS)
- {
- pCDS->DisableControls();
- }
- int nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- SrsType = GetChartType();
- /*
- * 합계 표출
- */
- kk = 0;
- if (nTotColIdx >= 0)
- {
- clSrsColor = GetDefaultColor(kk++);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(lblSoge->Caption/*"소계"*/, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- nTotColIdx = TvList->DataController->Summary->FooterSummaryItems->IndexOfItemLink(TvList->Columns[jj]);
- if (!VarIsNull(TvList->DataController->Summary->FooterSummaryValues[nTotColIdx]))
- {
- double dValX = 0;
- try {
- dValX = (double)TvList->DataController->Summary->FooterSummaryValues[nTotColIdx];
- } catch(...) { dValX = 0; }
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- }
- for (ii = 0; ii < nRows; ii++, kk++)
- {
- try
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- String sTitle = "";
- if (!VarIsNull(sTitle = ARow->Values[nAxisY]))
- {
- sTitle = ARow->Values[nAxisY];
- }
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- double dValX = 0;
- if (!VarIsNull(ARow->Values[jj]))
- try { dValX = (double)ARow->Values[jj]; } catch(...) {dValX=0;}
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- catch(...)
- {
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY(); // 그래프 생성
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1; // 그래프 그리기
- }
- }
- __finally
- {
- if (pCDS)
- {
- pCDS->EnableControls();
- }
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate(); //챠트 생성
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 해당되지 않는 컬럼을 클리어한다.
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::DrawChart4(TcxGridDBTableView *TvList, int nAxisY1, int nAxisY2, int nStColIdx, int nTotColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TClientDataSet *pCDS = NULL;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- pCDS = (TClientDataSet *)TvList->DataController->DataSource->DataSet;
- if (pCDS)
- {
- pCDS->DisableControls();
- }
- int nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- SrsType = GetChartType();
- /*
- * 합계 표출
- */
- kk = 0;
- if (nTotColIdx >= 0)
- {
- clSrsColor = GetDefaultColor(kk++);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(lblSoge->Caption/*"소계"*/, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- nTotColIdx = TvList->DataController->Summary->FooterSummaryItems->IndexOfItemLink(TvList->Columns[jj]);
- if (!VarIsNull(TvList->DataController->Summary->FooterSummaryValues[nTotColIdx]))
- {
- double dValX = 0;
- try {
- dValX = (double)TvList->DataController->Summary->FooterSummaryValues[nTotColIdx];
- } catch(...) { dValX = 0; }
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- }
- for (ii = 0; ii < nRows; ii++, kk++)
- {
- try
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- String sTitle = "";
- if (!VarIsNull(ARow->Values[nAxisY1]))
- {
- sTitle = ARow->Values[nAxisY1];
- }
- if (!VarIsNull(ARow->Values[nAxisY2]))
- {
- sTitle += ":";
- sTitle += ARow->Values[nAxisY2];
- }
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- double dValX = 0;
- String sVal = ARow->Values[jj];
- if (!VarIsNull(ARow->Values[jj]))
- try { dValX = (double)ARow->Values[jj]; } catch(...) {dValX=0;}
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- catch(...)
- {
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1;
- }
- }
- __finally
- {
- if (pCDS)
- {
- pCDS->EnableControls();
- }
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate();
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPlugInChart::DrawChart5(TcxGridDBTableView *TvList, int nAxisY1, int nAxisY2, int nAxisY3, int nStColIdx, int nEdColIdx/*=-1*/,int nTotColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TClientDataSet *pCDS = NULL;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- pCDS = (TClientDataSet *)TvList->DataController->DataSource->DataSet;
- if (pCDS)
- {
- pCDS->DisableControls();
- }
- int nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- if (nEdColIdx != -1)
- {
- nCols = nCols > nEdColIdx ? nEdColIdx+1 : nCols;
- }
- SrsType = GetChartType();
- /*
- * 합계 표출
- */
- kk = 0;
- if (nTotColIdx >= 0)
- {
- clSrsColor = GetDefaultColor(kk++);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(lblSoge->Caption/*"소계"*/, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- nTotColIdx = TvList->DataController->Summary->FooterSummaryItems->IndexOfItemLink(TvList->Columns[jj]);
- if (!VarIsNull(TvList->DataController->Summary->FooterSummaryValues[nTotColIdx]))
- {
- double dValX = 0;
- try {
- dValX = (double)TvList->DataController->Summary->FooterSummaryValues[nTotColIdx];
- } catch(...) { dValX = 0;}
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- }
- for (ii = 0; ii < nRows; ii++, kk++)
- {
- try
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- String sTitle = "";
- if (TvList->Columns[nAxisY1]->Visible && !VarIsNull(ARow->Values[nAxisY1]))
- {
- sTitle = ARow->Values[nAxisY1];
- }
- if (TvList->Columns[nAxisY2]->Visible && !VarIsNull(ARow->Values[nAxisY2]))
- {
- sTitle += ":";
- sTitle += ARow->Values[nAxisY2];
- }
- if (TvList->Columns[nAxisY3]->Visible && !VarIsNull(ARow->Values[nAxisY3]))
- {
- sTitle += ":";
- sTitle += ARow->Values[nAxisY3];
- }
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- double dValX = 0;
- if (!VarIsNull(ARow->Values[jj]))
- {
- String sVal = VarToStr(ARow->Values[jj]);
- try {
- //dValX = (double)ARow->Values[jj];
- dValX = (double)sVal.ToIntDef(0);
- } catch(...) {
- dValX=0;
- }
- }
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- catch(...)
- {
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1;
- }
- }
- __finally
- {
- if (pCDS)
- {
- pCDS->EnableControls();
- }
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate();
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPlugInChart::DrawChart5_1(TcxGridTableView *TvList, int nAxisY1, int nAxisY2, int nStColIdx, int nEdColIdx/*=-1*/,int nTotColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- int nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- if (nEdColIdx != -1)
- {
- nCols = nCols > nEdColIdx ? nEdColIdx+1 : nCols;
- }
- SrsType = GetChartType();
- /*
- * 합계 표출
- */
- kk = 0;
- if (nTotColIdx >= 0)
- {
- clSrsColor = GetDefaultColor(kk++);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(lblSoge->Caption/*"소계"*/, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- nTotColIdx = TvList->DataController->Summary->FooterSummaryItems->IndexOfItemLink(TvList->Columns[jj]);
- if (!VarIsNull(TvList->DataController->Summary->FooterSummaryValues[nTotColIdx]))
- {
- double dValX = 0;
- try {
- dValX = (double)TvList->DataController->Summary->FooterSummaryValues[nTotColIdx];
- } catch(...) { dValX = 0;}
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- }
- for (ii = 0; ii < nRows; ii++, kk++)
- {
- try
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- String sTitle = "";
- if (TvList->Columns[nAxisY1]->Visible && !VarIsNull(ARow->Values[nAxisY1]))
- {
- sTitle = ARow->Values[nAxisY1];
- }
- if (TvList->Columns[nAxisY2]->Visible && !VarIsNull(ARow->Values[nAxisY2]))
- {
- sTitle += ":";
- sTitle += ARow->Values[nAxisY2];
- }
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- double dValX = 0;
- if (!VarIsNull(ARow->Values[jj]))
- {
- String sVal = VarToStr(ARow->Values[jj]);
- try {
- //dValX = (double)ARow->Values[jj];
- dValX = (double)sVal.ToIntDef(0);
- } catch(...) {
- dValX=0;
- }
- }
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- catch(...)
- {
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1;
- }
- }
- __finally
- {
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate();
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TPlugInChart::DrawChart6(TcxGridDBTableView *TvList, int nAxisY1, int nAxisY2, int nAxisY3, int nStColIdx, int nEdColIdx/*=-1*/,int nTotColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TClientDataSet *pCDS = NULL;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- pCDS = (TClientDataSet *)TvList->DataController->DataSource->DataSet;
- if (pCDS)
- {
- pCDS->DisableControls();
- }
- int nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- if (nEdColIdx != -1)
- {
- nCols = nCols > nEdColIdx ? nEdColIdx+1 : nCols;
- }
- SrsType = GetChartType();
- /*
- * 합계 표출
- */
- kk = 0;
- if (nTotColIdx >= 0)
- {
- clSrsColor = GetDefaultColor(kk++);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(lblSoge->Caption/*"소계"*/, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- nTotColIdx = TvList->DataController->Summary->FooterSummaryItems->IndexOfItemLink(TvList->Columns[jj]);
- if (!VarIsNull(TvList->DataController->Summary->FooterSummaryValues[nTotColIdx]))
- {
- double dValX = 0;
- try {
- dValX = (double)TvList->DataController->Summary->FooterSummaryValues[nTotColIdx];
- } catch(...) { dValX = 0;}
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- }
- for (ii = 0; ii < nRows; ii++, kk++)
- {
- try
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
- String sTitle1, sTitle2;
- if (TvList->Columns[nAxisY1]->Visible && !VarIsNull(ARow->Values[nAxisY1]))
- {
- sTitle1 = ARow->Values[nAxisY1];
- }
- if (TvList->Columns[nAxisY2]->Visible && !VarIsNull(ARow->Values[nAxisY2]))
- {
- sTitle2 = ARow->Values[nAxisY2];
- }
- if (sTitle1 == sTitle2)
- {
- //그룹핑했을 경우 그룹핑한 컬럼 제외
- //continue;
- }
- if (!ARow->IsData) continue;
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- String sTitle = sTitle1 + ":" + sTitle2;
- #if 0
- if (TvList->Columns[nAxisY3]->Visible && !VarIsNull(ARow->Values[nAxisY3]))
- {
- sTitle += ":";
- sTitle += ARow->Values[nAxisY3];
- }
- #endif
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- double dValX = 0;
- if (!VarIsNull(ARow->Values[jj]))
- {
- String sVal = VarToStr(ARow->Values[jj]);
- try {
- //dValX = (double)ARow->Values[jj];
- dValX = (double)sVal.ToIntDef(0);
- } catch(...) {
- dValX=0;
- }
- }
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- catch(...)
- {
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1;
- }
- }
- __finally
- {
- if (pCDS)
- {
- pCDS->EnableControls();
- }
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate();
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 해당되지 않는 컬럼을 클리어한다.
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::DrawChart3(TcxGridDBTableView *TvList, int nAxisY1, int nAxisY2, int nStColIdx, int nTotColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TClientDataSet *pCDS = NULL;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- pCDS = (TClientDataSet *)TvList->DataController->DataSource->DataSet;
- if (pCDS)
- {
- pCDS->DisableControls();
- }
- int nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- SrsType = GetChartType();
- /*
- * 합계 표출
- */
- kk = 0;
- if (nTotColIdx >= 0)
- {
- clSrsColor = GetDefaultColor(kk++);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(lblSoge->Caption/*"소계"*/, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- nTotColIdx = TvList->DataController->Summary->FooterSummaryItems->IndexOfItemLink(TvList->Columns[jj]);
- if (!VarIsNull(TvList->DataController->Summary->FooterSummaryValues[nTotColIdx]))
- {
- double dValX = 0;
- try {
- dValX = (double)TvList->DataController->Summary->FooterSummaryValues[nTotColIdx];
- } catch(...) { dValX = 0; }
-
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- }
- for (ii = 0; ii < nRows; ii++, kk++)
- {
- try
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[ii];
- String sTitle, sTitle1, sTitle2;
- sTitle = "";
- sTitle1 = "";
- sTitle2 = "";
- if (!VarIsNull(ARow->Values[nAxisY1]))
- sTitle1 = ARow->Values[nAxisY1];
- if (!VarIsNull(ARow->Values[nAxisY2]))
- sTitle2 = ARow->Values[nAxisY2];
- if (sTitle2 == FrmLang->lblChartSoge->Caption)//"소계")
- continue;
- if (sTitle2 == "")
- {
- sTitle = sTitle1;
- }
- else
- {
- sTitle = sTitle1 + ":" + sTitle2;
- }
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- if (pSeries)
- {
- for (jj = nStColIdx; jj < nCols; jj++)
- {
- if (!TvList->Columns[jj]->Visible)
- {
- break;
- }
- String sAxisX = TvList->Columns[jj]->Caption;
- double dValX = 0;
- if (!VarIsNull(ARow->Values[jj]))
- try { dValX = (double)ARow->Values[jj]; } catch(...) {dValX=0;}
- pSeries->AddY(dValX, sAxisX);
- }
- }
- }
- catch(...)
- {
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1;
- }
- }
- __finally
- {
- if (pCDS)
- {
- pCDS->EnableControls();
- }
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate();
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 해당되지 않는 컬럼을 클리어한다.
- * arguments
- *
- * return
- * void
- */
- void __fastcall TPlugInChart::DrawChart2(TcxGridDBBandedTableView *TvList,
- int nAxisY, int nStColIdx,
- int nTotColIdx/*=-1*/,
- bool bBarSeries/*=true*/,
- bool bBandText/*=true*/,
- int nEdColIdx/*=-1*/)
- {
- int ii, jj, kk;
- SeriesType SrsType;
- TColor clSrsColor;
- TChartSeries *pSeries;
- TClientDataSet *pCDS = NULL;
- TcxGridBand *pBand;
- TcxGridDBBandedColumn *pCol;
- TCursor cOldCursor= Screen->Cursor;
- try
- {
- Screen->Cursor = crHourGlass;
- LstLegend->Items->BeginUpdate();
- TvList->BeginUpdate();
- pCDS = (TClientDataSet *)TvList->DataController->DataSource->DataSet;
- if (pCDS)
- {
- pCDS->DisableControls();
- }
- int nCols;
- if (nEdColIdx >= 0)
- nCols = nEdColIdx+1;
- else
- nCols = TvList->ColumnCount;
- int nRows = TvList->ViewData->RecordCount;
- SrsType = GetChartType();
- for (ii = nStColIdx; ii < nCols; ii++, kk++)
- {
- pCol = TvList->Columns[ii];
- if (!pCol)
- {
- continue;
- }
- if (!pCol->Visible)
- continue;
- pBand = TvList->Bands->Items[pCol->Position->BandIndex];
- clSrsColor = GetDefaultColor(kk);
- if (clSrsColor == clWhite) clSrsColor = GetDefaultColor(++kk);
- if (clSrsColor == clYellow) clSrsColor = GetDefaultColor(++kk);
- String sTitle;
- if (bBandText)
- {
- sTitle = "[" + pBand->Caption + "]" + pCol->Caption;
- }
- else
- {
- sTitle = pCol->Caption;
- }
- if (ii == nTotColIdx)
- sTitle = pCol->Caption;
- if (ii == nTotColIdx && bBarSeries)
- {
- pSeries = AddSeriesItem(sTitle, ctpBar, clSrsColor, true);
- }
- else
- {
- pSeries = AddSeriesItem(sTitle, SrsType, clSrsColor, true);
- }
- for (jj = 0; jj < nRows; jj++)
- {
- TcxCustomGridRow* ARow = TvList->ViewData->Rows[jj];
- String sX = "";
- if (!VarIsNull(ARow->Values[nAxisY]))
- try { sX = ARow->Values[nAxisY]; } catch(...) {}
- double nY = 0;
- if (!VarIsNull(ARow->Values[ii]))
- try { nY = (double)ARow->Values[ii]; } catch(...){nY=0;};
- pSeries->AddY(nY, sX);
- }
- }
- DbChart->LeftAxis->Minimum = 0;
- DbChart->LeftAxis->Maximum = GetActiveMaxY();
- if (DbChart->LeftAxis->Minimum >= DbChart->LeftAxis->Maximum)
- {
- DbChart->LeftAxis->Maximum = DbChart->LeftAxis->Minimum + 1;
- }
- }
- __finally
- {
- if (pCDS)
- {
- pCDS->EnableControls();
- }
- TvList->EndUpdate();
- DbChart->Refresh();
- LstLegend->Items->EndUpdate();
- Screen->Cursor = cOldCursor;
- }
- }
- //---------------------------------------------------------------------------
- /*
- * 차트 그린후 호출(Optional)
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::EndDraw()
- {
- BtnChkAllClick(NULL);
- }
- //---------------------------------------------------------------------------
- SeriesType __fastcall TPlugInChart::GetChartType()
- {
- return (SeriesType)CbChartKind->ItemIndex;
- }
- //---------------------------------------------------------------------------
- /*
- * 차트에 차트시리즈를 추가한다.
- *
- * arguments
- * return
- * void
- */
- TChartSeries* __fastcall TPlugInChart::AddSeriesItem(String sTitle,
- SeriesType SrsType,
- TColor clSrsColor,
- bool bActive/*=true*/
- )
- {
- SeriesItem *pSrsItem;
- TChartSeries *pSeries = NULL;
- try
- {
- pSrsItem = new SeriesItem;
- pSrsItem->SrsType = SrsType;
- pSeries = MakeChartSeries(SrsType);
- pSeries->Title = sTitle;
- pSrsItem->ChartSeries = (void*)pSeries;
- pSeries->Active = bActive;
- pSeries->SeriesColor = clSrsColor;
- LstLegend->Items->AddObject(sTitle, (TObject*)pSrsItem);
- LstLegend->Checked[LstLegend->Count-1] = bActive;
- pSeries->ParentChart = DbChart;
- }
- catch(...)
- {
- }
- return pSeries;
- }
- //---------------------------------------------------------------------------
- /*
- * 차트시리즈를 생성한다.
- *
- * arguments
- * return
- * void
- */
- TChartSeries* __fastcall TPlugInChart::MakeChartSeries(SeriesType nSeriesTp)
- {
- TChartSeries *pSeries = NULL;
- try
- {
- switch(nSeriesTp)
- {
- case ctpLine:
- {
- TLineSeries *pChart = new TLineSeries(this);
- pChart->Pointer->Style = psRectangle;
- pChart->Pointer->Visible = true;
- pChart->Pointer->VertSize = 4;
- //pChart->Marks->Style = smsValue;
- //pChart->Marks->Visible = false;
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpBar:
- {
- TBarSeries *pChart = new TBarSeries(this);
- pChart->Marks->Visible = true;
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpHorizontal_Bar:
- {
- THorizBarSeries *pChart = new THorizBarSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpArea:
- {
- TAreaSeries *pChart = new TAreaSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpPoint:
- {
- TPointSeries *pChart = new TPointSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpPie:
- {
- TPieSeries *pChart = new TPieSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpFast_Line:
- {
- TFastLineSeries *pChart = new TFastLineSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpHorizontal_Line:
- {
- THorizLineSeries *pChart = new THorizLineSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpHorizontal_Area:
- {
- THorizAreaSeries *pChart = new THorizAreaSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpShape:
- {
- TChartShape *pChart = new TChartShape(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpGantt:
- {
- TGanttSeries *pChart = new TGanttSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpArrow:
- {
- TArrowSeries *pChart = new TArrowSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- case ctpBubble:
- {
- TBubbleSeries *pChart = new TBubbleSeries(this);
- pSeries = (TChartSeries *)pChart;
- }
- break;
- }
- pSeries->Marks->Style = smsValue;
- pSeries->Marks->Visible = ChkDispValue->Checked;
- }
- catch(...)
- {
- }
- return pSeries;
- }
- //---------------------------------------------------------------------------
- /*
- * Bar 차트시리즈를 생성한다.
- *
- * arguments
- * return
- * void
- */
- void __fastcall TPlugInChart::ShowBarChart()
- {
- #if 0
- chart.RemoveAllSeries();
- if (ds.rowcount == 0) return;
- var i = 0, serindex = 0;
- var oldvalue = "", newvalue = "";
- while (i < ds.rowcount)
- {
- newvalue = ds.GetColumn(i,"D1");
- if (oldvalue != newvalue) {
- //시리즈 추가
- chart.addSeries (1); //scBar
- chart.Series(serindex).Clear();
- chart.Series(serindex).title = newvalue;
- chart.Series(serindex).Name = newvalue;
- chart.Series(serindex).Marks.Style = 0; //smsValue;
- chart.Series(serindex).Marks.Visible = false;
- chart.Series(serindex).color = arrseror[serindex % arrseror.length];
- serindex++;
- oldvalue = newvalue;
- }
- var xname = ds.GetColumn(i,"D2"); //X축 명칭
- var xvalue = ds.GetColumn(i,"D3"); //X축 값
- chart.Series(serindex-1).Add (toNumber(xvalue), xname, chart.Series(serindex-1).color);
- chart.Series(serindex-1).Marks.Style = 0; //smsValue //마크에 표시될 내용
- chart.Series(serindex-1).Marks.Frame.Color = TCH_MARK_BORDERCOLOR; //마크 테두리 색상
- i++;
- }
- #endif
- }
- //---------------------------------------------------------------------------
- void __fastcall TPlugInChart::DbChartClickSeries(TCustomChart *Sender, TChartSeries *Series, int ValueIndex, TMouseButton Button, TShiftState Shift,
- int X, int Y)
- {
- #if 0
- try
- {
- double vx, vy;
- AnsiString s;
- Sender->GetCursorValues(vx, vy);
- int nValue = Sender->GetMarkValue(floor(vx+0.50)-1);
- acDragPanel1->Color = Sender->Tag;
- AnsiString sTP = (AnsiString)tvList->Columns[2+ValueIndex]->Caption;
- s = sTP + "\n" + Sender->Title + "\n" + IntToStr(nValue) + lblEA->Caption;//"건";
- LblDet->Caption = s;
- LblDet->Left = 6;
- LblDet->Top = 6;
- acDragPanel1->Width = LblDet->Left+LblDet->Width+8;
- acDragPanel1->Height = LblDet->Left+LblDet->Height+8;
- acDragPanel1->Left = X + 5;
- if((Sender->ParentChart->Height - Y) <= acDragPanel1->Height)
- acDragPanel1->Top = Y - acDragPanel1->Height;
- else
- acDragPanel1->Top = Y;
- acDragPanel1->Visible = true;
- }
- catch(...)
- {
- }
- #endif
- if (Button != mbLeft)
- {
- return;
- }
- String sMsg;
- //double vx, vy;
- //Series->GetCursorValues(vx, vy);
- //int nValue = Series->GetMarkValue(floor(vx+0.50)-1);
- //ShowMessage(String(ValueIndex));
- //Series->Labels->
- sMsg = Series->Title + "\r\n";
- //sMsg += Series->Labels[ValueIndex].ToString() + "\r\n";
- // sMsg+= String(Series->XValues->Value[ValueIndex]) + " " + DbChart->BottomAxis->Title->Caption + "\r\n";
- sMsg+= DbChart->LeftAxis->Title->Caption + ": " + String(Series->YValues->Value[ValueIndex]);
- ShowMessage(sMsg);
- }
- //---------------------------------------------------------------------------
- void __fastcall TPlugInChart::DbChartMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
- {
- #if 0
- int idx=Series1->GetCursorValueIndex();
- if(idx>=0)
- {
- double dX,dY;
- Series1->GetCursorValues(dX,dY);
- Chart1->Hint="( "+IntToStr((int)dX)+" , "+IntToStr((int)dY)+ " )";
- }
- else
- {
- Chart1->Hint="";
- }
- #endif
- }
- //---------------------------------------------------------------------------
|