株価チャート

SPREADでは以下の3種類の株価チャートが提供されています。 チャートはエンドユーザーが自由に移動したりリサイズすることができます。

株価チャート(高値-安値-終値)株価チャート(始値-高値-安値-終値)ローソク足
 ABCDEF
1 8/18/28/38/48/5
2Open864279825360384
3High926614865562650
4Low500146501310260
5Close650560786486428
   

ソースコード

別ウィンドウで表示
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class chart_stockchart : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            return;
        }

        // SPREADの設定
        InitSpread(FpSpread1);

        // シート設定
        InitSpreadStyles(FpSpread1.Sheets[0]);
    }

    private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
    {
        spread.CssClass = "spreadStyle2";
        spread.UseClipboard = false;
    }

    private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet)
    {
        // フォントサイズの設定
        sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%");
        sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
        sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%");
        sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%");

        sheet.RowCount = 5;
        sheet.ColumnCount = 6;

        // 2Dを選択
        RadioButtonList1.SelectedIndex = 0;

        // テストデータの設定
        sheet.SetClipValue(0, 1, 1, 5, "8/1\t8/2\t8/3\t8/4\t8/5");
        sheet.SetClipValue(1, 0, 1, 6, "Open\t864\t279\t825\t360\t384");
        sheet.SetClipValue(2, 0, 1, 6, "High\t926\t614\t865\t562\t650");
        sheet.SetClipValue(3, 0, 1, 6, "Low\t500\t146\t501\t310\t260");
        sheet.SetClipValue(4, 0, 1, 6, "Close\t650\t560\t786\t486\t428");

        // シリーズを作成
        FarPoint.Web.Chart.CandlestickSeries series1 = new FarPoint.Web.Chart.CandlestickSeries();
        series1.SeriesName = "Series 1";
        series1.CategoryNames.DataSource = new FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldCategoryName", "Sheet1!$B$1:$F$1", FarPoint.Web.Spread.Chart.SegmentDataType.Text);
        series1.CloseValues.DataSource = new FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue3", "Sheet1!$B$5:$F$5");
        series1.HighValues.DataSource = new FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue1", "Sheet1!$B$3:$F$3");
        series1.LowValues.DataSource = new FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue2", "Sheet1!$B$4:$F$4");
        series1.OpenValues.DataSource = new FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue0", "Sheet1!$B$2:$F$2");

        // プロット領域を作成します
        FarPoint.Web.Chart.YPlotArea plotArea = new FarPoint.Web.Chart.YPlotArea();
        plotArea.Location = new System.Drawing.PointF(0.2f, 0.2f);
        plotArea.Size = new System.Drawing.SizeF(0.6f, 0.6f);
        plotArea.XAxis.MajorGridVisible = true;
        plotArea.Series.AddRange(new FarPoint.Web.Chart.Series[] { series1 });

        // チャートモデルに各情報を追加します
        FarPoint.Web.Chart.ChartModel model = new FarPoint.Web.Chart.ChartModel();
        model.PlotAreas.Add(plotArea);

        // SPREADチャートにチャートモデルを設定します
        FarPoint.Web.Spread.Chart.SpreadChart chart = new FarPoint.Web.Spread.Chart.SpreadChart();
        chart.Height = 300;
        chart.Width = 400;
        chart.Left = 50;
        chart.Top = 120;
        chart.Model = model;

        sheet.Charts.Add(chart);
    }
    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        FpSpread1.SaveChanges();

        if (FpSpread1.ActiveSheetView.Charts.Count > 0)
        {
            if (RadioButtonList1.SelectedIndex == 1)
            {
                FpSpread1.ActiveSheetView.Charts[0].ViewType = FarPoint.Web.Chart.ChartViewType.View3D;
                FpSpread1.ActiveSheetView.Charts[0].Model.PlotAreas[0].Elevation = 18;
                FpSpread1.ActiveSheetView.Charts[0].Model.PlotAreas[0].Rotation = -24;
            }
            else
            {
                FpSpread1.ActiveSheetView.Charts[0].ViewType = FarPoint.Web.Chart.ChartViewType.View2D;
            }
        }
    }
}

Partial Class chart_stockchart
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack Then
            Return
        End If

        ' SPREADの設定
        InitSpread(FpSpread1)

        ' シート設定
        InitSpreadStyles(FpSpread1.Sheets(0))
    End Sub

    Private Sub InitSpread(ByVal spread As FarPoint.Web.Spread.FpSpread)
        spread.CssClass = "spreadStyle2"
        spread.UseClipboard = False
    End Sub

    Private Sub InitSpreadStyles(ByVal sheet As FarPoint.Web.Spread.SheetView)
        ' フォントサイズの設定
        sheet.DefaultStyle.Font.Size = FontUnit.Parse("80%")
        sheet.ColumnHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
        sheet.RowHeader.DefaultStyle.Font.Size = FontUnit.Parse("80%")
        sheet.SheetCorner.DefaultStyle.Font.Size = FontUnit.Parse("80%")

        sheet.RowCount = 5
        sheet.ColumnCount = 6

        ' 2Dを選択
        RadioButtonList1.SelectedIndex = 0

        ' テストデータの設定
        sheet.SetClipValue(0, 1, 1, 5, "8/1" & vbTab & "8/2" & vbTab & "8/3" & vbTab & "8/4" & vbTab & "8/5")
        sheet.SetClipValue(1, 0, 1, 6, "Open" & vbTab & "864" & vbTab & "279" & vbTab & "825" & vbTab & "360" & vbTab & "384")
        sheet.SetClipValue(2, 0, 1, 6, "High" & vbTab & "926" & vbTab & "614" & vbTab & "865" & vbTab & "562" & vbTab & "650")
        sheet.SetClipValue(3, 0, 1, 6, "Low" & vbTab & "500" & vbTab & "146" & vbTab & "501" & vbTab & "310" & vbTab & "260")
        sheet.SetClipValue(4, 0, 1, 6, "Close" & vbTab & "650" & vbTab & "560" & vbTab & "786" & vbTab & "486" & vbTab & "428")

        ' シリーズを作成
        Dim series1 As New FarPoint.Web.Chart.CandlestickSeries()
        series1.SeriesName = "Series 1"
        series1.CategoryNames.DataSource = New FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldCategoryName", "Sheet1!$B$1:$F$1", FarPoint.Web.Spread.Chart.SegmentDataType.Text)
        series1.CloseValues.DataSource = New FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue3", "Sheet1!$B$5:$F$5")
        series1.HighValues.DataSource = New FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue1", "Sheet1!$B$3:$F$3")
        series1.LowValues.DataSource = New FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue2", "Sheet1!$B$4:$F$4")
        series1.OpenValues.DataSource = New FarPoint.Web.Spread.Chart.SeriesDataField(FpSpread1, "DataFieldValue0", "Sheet1!$B$2:$F$2")

        ' プロット領域を作成します
        Dim plotArea As New FarPoint.Web.Chart.YPlotArea()
        plotArea.Location = New System.Drawing.PointF(0.2F, 0.2F)
        plotArea.Size = New System.Drawing.SizeF(0.6F, 0.6F)
        plotArea.XAxis.MajorGridVisible = True
        plotArea.Series.AddRange(New FarPoint.Web.Chart.Series() {series1})

        ' チャートモデルに各情報を追加します
        Dim model As New FarPoint.Web.Chart.ChartModel()
        model.PlotAreas.Add(plotArea)

        ' SPREADチャートにチャートモデルを設定します
        Dim chart As New FarPoint.Web.Spread.Chart.SpreadChart()
        chart.Height = 300
        chart.Width = 400
        chart.Left = 50
        chart.Top = 120
        chart.Model = model

        sheet.Charts.Add(chart)
    End Sub

    Protected Sub RadioButtonList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadioButtonList1.SelectedIndexChanged
        FpSpread1.SaveChanges()

        If FpSpread1.ActiveSheetView.Charts.Count > 0 Then
            If RadioButtonList1.SelectedIndex = 1 Then
                FpSpread1.ActiveSheetView.Charts(0).ViewType = FarPoint.Web.Chart.ChartViewType.View3D
                FpSpread1.ActiveSheetView.Charts(0).Model.PlotAreas(0).Elevation = 18
                FpSpread1.ActiveSheetView.Charts(0).Model.PlotAreas(0).Rotation = -24
            Else
                FpSpread1.ActiveSheetView.Charts(0).ViewType = FarPoint.Web.Chart.ChartViewType.View2D
            End If
        End If
    End Sub
End Class

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="stockchart.aspx.cs" Inherits="chart_stockchart" %>

<%@ Register Assembly="FarPoint.Web.SpreadJ" Namespace="FarPoint.Web.Spread" TagPrefix="FarPoint" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeaderPlaceHolder1" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" 
        RepeatDirection="Horizontal" 
        onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">
        <asp:ListItem Selected="True">2D</asp:ListItem>
        <asp:ListItem>3D</asp:ListItem>
    </asp:RadioButtonList> 
    <FarPoint:FpSpread ID="FpSpread1" runat="server" BorderColor="#A0A0A0" BorderStyle="Solid"
        BorderWidth="1px">
        <CommandBar BackColor="#F6F6F6" ButtonFaceColor="Control" ButtonHighlightColor="ControlLightLight"
            ButtonShadowColor="ControlDark">
        </CommandBar>
        <Sheets>
            <FarPoint:SheetView SheetName="Sheet1">
            </FarPoint:SheetView>
        </Sheets>
    </FarPoint:FpSpread>
</asp:Content>