0

我有两个问题:

  1. 我想要数据表中的名称,但它以数字形式显示。

  2. 我想在两个酒吧之间留一个空隙,但我找不到办法。

这是代码:

私有无效 InitializeGraph (DataTable poDt) { Telerik.Charting.ChartSeries charteries = new Telerik.Charting.ChartSeries();

    try
    {


        chartseries.Type = Telerik.Charting.ChartSeriesType.Bar;

        Telerik.Charting.ChartSeriesItem csItem;

        RadChart1.PlotArea.XAxis.AutoScale = true;
        RadChart1.PlotArea.XAxis.DataLabelsColumn = "Name";


        for (int iRow = 0; iRow < poDt.Rows.Count; iRow++)
        {
            chartseries = new Telerik.Charting.ChartSeries();

            chartseries.Type = Telerik.Charting.ChartSeriesType.Bar;

            chartseries.Name = poDt.Rows[iRow]["Name"].ToString().Trim();


            csItem = new Telerik.Charting.ChartSeriesItem();
            csItem.Name = poDt.Rows[iRow]["Name"].ToString();
            csItem.Label.TextBlock.Text = poDt.Rows[iRow]["Value"].ToString(); 
            RadChart1.PlotArea.XAxis.Appearance.TextAppearance.AutoTextWrap = Telerik.Charting.Styles.AutoTextWrap.True;

            csItem.YValue = Int32.Parse(poDt.Rows[iRow]["Value"].ToString());

            chartseries.AddItem(csItem);
            RadChart1.Series.Add(chartseries);

        }
        RadChart1.PlotArea.XAxis.AddRange(1, poDt.Rows.Count, 1);

        RadChart1.PlotArea.XAxis[poDt.Rows.Count].TextBlock.Text = chartseries.Name;
        poDt.Rows.Count.ToString();
        RadChart1.PlotArea.XAxis.AutoShrink = false;


        RadChart1.PlotArea.XAxis.AutoShrink = true;
        RadChart1.Series.Add(chartseries);

        RadChart1.PlotArea.Appearance.Border.Visible = false;
        RadChart1.Appearance.Border.Visible = true;
        RadChart1.PlotArea.YAxis.IsLogarithmic = true;

        RadChart1.PlotArea.YAxis.AutoScale = true;
        RadChart1.PlotArea.YAxis.Appearance.ValueFormat=Telerik.Charting.Styles.ChartValueFormat.Number;
        RadChart1.Appearance.BarWidthPercent = 50;



        RadChart1.Chart.Appearance.FillStyle.MainColor = System.Drawing.Color.Red;
        RadChart1.Chart.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;
        RadChart1.Legend.Appearance.FillStyle.MainColor = System.Drawing.Color.Transparent;

    }
    catch (Exception Ex)
    {
        //throw;
    }
    finally
    {
        poDt.Clear();
        poDt = null;
        chartseries = null;
    }
}
4

1 回答 1

0

抱歉,我不相信有办法同时显示两个 X 轴。

我的建议是您使用 CategoricalAxis 作为您的 X 轴并创建一个自定义条形图,该条形图具有区分这两个值的图例。我没有任何工作示例,但是您可以将这个Telerik Silverlight演示用于初学者。

此外,如果可以,请切换到 RadChartView。因为我会建议一种更简单的方法,即使用分类 X 轴并创建多个 Y 轴。如果您走那条路线,您可以对具有多个 Y 轴的 DateTimeContinuous(或分类)X 轴执行类似的操作:

int count = 0;
LineSeries lineSeries = new LineSeries();

lineSeries.CategoryBinding = new PropertyNameDataPointBinding() { PropertyName = "TimeStamp" };
lineSeries.ValueBinding = new PropertyNameDataPointBinding() { PropertyName = "Value" };  

lineSeries.VerticalAxis = new LinearAxis()
{
   Title = "Title Here"
};

lineSeries.ItemsSource = yourCollection.Values;

//First Y-axis to be placed on the left of X-axis,
//additional Y-axes to be placed on right
if (count > 0 )
{
     lineSeries.VerticalAxis.HorizontalLocation = Telerik.Charting.AxisHorizontalLocation.Right;
}
count++;
chartName.Series.Add(lineSeries);

希望这可以帮助。

于 2013-01-08T22:18:45.700 回答