リスト7 株価チャート(メイン・アプリケーション)

<?xml version="1.0" encoding="UTF-8" ?>
<canvas>
  <include href="dailychart.lzx"/>
  <include href="stockdata.lzx"/>
  <include href="complexchartclass.lzx"/>  <!--今回の組み込み分 1/3 -->

  <dataset name="meigara">
    <company id="1">(株)ABC社</company>
    <company id="2">(株)XYZ社</company>
  </dataset>

  <dataset name="stockdaily">
    <records>
      <record time="9"  price="9980"/>
      <record time="10" price="10000"/>
      <record time="11" price="10010"/>
      <record time="12" price="10010"/>
    </records>
    <stockprice todaymax="10,010" todaymin="9,980" nowprice="10,010"/>
  </dataset>

  <dataset name="stockdata">
    <records>
      <record date="6/1" start="10,010" hight="10,050"
              low="10,010" end="10,040" ratio="+30" deal="100"/>
      <record date="6/2" start="10,040" hight="10,050"
              low="10,010" end="10,010" ratio="-30" deal="100"/>
      <record date="6/3" start="10,010" hight="10,050"
              low="10,010" end="10,040" ratio="+30" deal="100"/>
      <record date="6/4" start="10,040" hight="10,050"
              low="10,010" end="10,010" ratio="-30" deal="100"/>
      <record date="6/5" start="10,010" hight="10,050"
              low="10,010" end="10,040" ratio="+30" deal="100"/>
      <record date="6/6" start="10,040" hight="10,050"
              low="10,010" end="10,010" ratio="-30" deal="100"/>
      <record date="6/7" start="10,010" hight="10,050"
              low="10,010" end="10,040" ratio="+30" deal="100"/>
      <record date="6/8" start="10,040" hight="10,050"
              low="10,010" end="10,010" ratio="-30" deal="100"/>
      <record date="6/9" start="10,010" hight="10,050"
              low="10,010" end="10,040" ratio="+30" deal="100"/>
      <record date="6/10" start="10,040" hight="10,050"
              low="10,010" end="10,010" ratio="-30" deal="100"/>
    </records>
  </dataset>

  <dataset name="stockprice">      <!--今回の組み込み分 2/3 -->
    <records>
        <record date="10" price="10100" average5="10081"
                volume="1000"/>
        <record date="11" price="10050" average5="10072"
                volume="800"/>
        <record date="12" price="10010" average5="10053"
                volume="600"/>
        <record date="13" price="10000" average5="10040"
                volume="600"/>
        <record date="14" price="9950"  average5="10022"
                volume="1000"/>
        <record date="15" price="9930"  average5="9988"
                volume="1000"/>
        <record date="16" price="9900"  average5="9990"
                volume="800"/>
        <record date="17" price="9900"  average5="9958"
                volume="600"/>
        <record date="18" price="9920"  average5="9942"
                volume="600"/>
        <record date="19" price="9930"  average5="9938"
                volume="1000"/>
        <record date="20" price="9910"  average5="9934"
                volume="1000"/>
        <record date="21" price="9930"  average5="9940"
                volume="800"/>
        <record date="22" price="9950"  average5="9950"
                volume="600"/>
        <record date="23" price="10010" average5="9968"
                volume="600"/>
        <record date="24" price="10100" average5="10002"
                volume="1000"/>
        <record date="25" price="10100" average5="10018"
                volume="1000"/>
        <record date="26" price="10120" average5="10056"
                volume="800"/>
        <record date="27" price="10130" average5="10092"
                volume="600"/>
        <record date="28" price="10110" average5="10112"
                volume="600"/>
        <record date="29" price="10100" average5="10112"
                volume="1000"/>
    </records>
  </dataset>

  <class name="chartview"
         onmousedown="bringToFront();drg.apply()"
         onmouseup="drg.remove()" clip="true">
    <dragstate name="drg"/>
    <method event="ony">
      <![CDATA[
        var upper_y = 0;
        var lower_y = canvas.height;
        var now_y   = this.y;
        var height  = this.height; 
        if( now_y < upper_y ) this.setAttribute( 'y', upper_y );
        if( lower_y < (now_y+height) )
            this.setAttribute( 'y', lower_y-height );
      ]]>
    </method>
    <method event="onx">
      <![CDATA[
        var left_x  = 0;
        var right_x = canvas.width;
        var now_x   = this.x;
        var width   = this.width;
        if( now_x < left_x ) this.setAttribute( 'x', left_x );
        if( right_x < (now_x+width) )
            this.setAttribute( 'x', right_x-width );
      ]]>
    </method>
  </class>
  
  <class name="chkb" extends="checkbox"
         fontsize="14" visible="false">
    <method event="onclick">
      Debug.write( this.text + ":" + this.value );
    </method>
  </class>

  <!-- 
    銘柄、表示チャート選択ビュー
   -->
  <view name="cont" width="${canvas.width}"
        height="${canvas.height*0.2}">
    <simplelayout axis="x"/>
    <!-- 銘柄選択 -->
    <view name="stocklist" width="${parent.width*0.4}"
          height="${parent.height}" bgcolor="red">
      <text x="50" y="20" fontsize="14">銘柄:</text>
      <combobox name="cbox" x="90" y="20"
                defaulttext="銘柄選択" editable="false">
        <textlistitem datapath="meigara:/company"
                      text="$path{'text()'}"
                      value="$path{'@id'}"/>
        <method event="onselect">
            var obj = this.getSelection();
            var id = obj.getValue();
            Debug.write( "id: " + id );

            with( canvas.cont.chartselect ){
              if( !cs1.visible ){
                for( var i=0; i<subviews.length; i++ ){
                  subviews[i].setVisible( true );
                }

                cs1.setValue( true );
              }
            }
        </method>
      </combobox>
    </view>
    <!-- 表示チャート選択 -->
    <view name="chartselect" width="${parent.width*0.6}"
          height="${parent.height}"  bgcolor="green">
      <chkb name="cs1" x="10" y="10" text="ローソク足・出来高チャート"/>
      <chkb name="cs2" x="10" y="30" text="当日株価チャート"/>
      <chkb name="cs3" x="10" y="50" text="過去株価一覧"/>
    </view>
  </view>
  <!-- 
    チャート表示ビュー
   -->
  <view name="chartarea" y="${parent.cont.height+1}"
        width="${canvas.width}" height="${canvas.height*0.8}">
    <!-- ローソク足・出来高チャートビュー -->
    <chartview name="candlechart" x="0" y="0"
               width="${parent.width/2}"
               height="${parent.height/2}"
               visible="${canvas.cont.chartselect.cs1.value}">
      <complexchart width="${parent.width}"
          height="${parent.height}"/>    <!--今回の組み込み分 3/3 -->
    </chartview>
    <!-- リアルタイム株価チャートビュー -->
    <chartview name="realtimechart" x="${parent.width/2}"
               y="0" width="${parent.width/2}"
               height="${parent.height/2}" bgcolor="silver"
               visible="${canvas.cont.chartselect.cs2.value}">
      <dailychart width="${parent.width}"
                  height="${parent.height}"/>
    </chartview>
    <!-- 株価一覧ビュー -->
    <chartview name="datalist" x="0" y="${parent.height/2}"
               width="${parent.width}" height="${parent.height/2}"
               bgcolor="yellow"
               visible="${canvas.cont.chartselect.cs3.value}">
      <stockdata width="${parent.width}"
                 height="${parent.height}"/>
    </chartview>
  </view>
</canvas>