1

グラフにバインドされているのとまったく同じデータ ソースから取得したプロパティを使用して、すべてのシリーズ ポイント値をカスタマイズしたいと考えています。私の問題を説明するために、DevExpress がWeb サイトでチャート データ バインディングのために行っているのと同じ例を使用します。

public class Record {
    int id, age;
    string name;
    public Record(int id, string name, int age) {
        this.id = id;
        this.name = name;
        this.age = age;
    }
    public int ID {
        get { return id; }
        set { id = value; }
    }
    public string Name {
        get { return name; }
        set { name = value; }
    }
    public int Age {
        get { return age; }
        set { age = value; }
    }
}

グラフを埋めるために、次のコード ブロックを使用します。

private void Form1_Load(object sender, EventArgs e) {
    // Create a list. 
    ArrayList listDataSource = new ArrayList();

    // Populate the list with records. 
    listDataSource.Add(new Record(1, "Jane", 19));
    listDataSource.Add(new Record(2, "Joe", 30));
    listDataSource.Add(new Record(3, "Bill", 15));
    listDataSource.Add(new Record(4, "Michael", 42));

    // Bind the chart to the list. 
    ChartControl myChart = chartControl1;
    myChart.DataSource = listDataSource;
    
    // Create a series, and add it to the chart. 
    Series series1 = new Series("My Series", ViewType.Bar);
    myChart.Series.Add(series1);

    // Adjust the series data members. 
    series1.ArgumentDataMember = "name";
    series1.ValueDataMembers.AddRange(new string[] { "age" });

    // Access the view-type-specific options of the series. 
    ((BarSeriesView)series1.View).ColorEach = true;
    series1.LegendPointOptions.Pattern = "{A}";
}

コードの結果のチャートは次のとおりです。

結果のチャート

私の質問は、たとえばプロパティを使用してID、すべてのシリーズラベルポイントに追加情報を追加するにはどうすればよいですか? (例: {ID + " - " + Age}) 前のグラフでは、「1 - 19」、「2 - 30」、「3 - 15」、および「4 - 42」というラベル データ ポイントを取得します。

4

3 に答える 3

0

凡例テキストに引数と値の両方をもたらす LegendPoint オプションを使用します。

series1.LegendPointOptions.PointView = PointView.ArgumentAndValues;

于 2014-01-18T12:04:46.707 に答える
0

コードの外観から、これはRecordオブジェクト内から行われます。

その Age パラメーターは整数であり、チャート ラベルにも一致します。そのラベルを変更するには、参照しているものを変更します。

次のような Record オブジェクトで新しいプロパティを作成します。

public string ChartLabel
{  get { return String.Format("{0} - {1}", ID, Age); } }

取得専用のプロパティです...次に、チャート コードを次のように変更します。

series1.ArgumentDataMember = "name";
series1.ValueDataMembers.AddRange(new string[] { "ChartLabel" });

これにより、チャートに表示される内容が変更されます。

于 2013-05-06T19:38:33.567 に答える