0

我收到以下异常:

DataBind() 行上的“输入字符串格式不正确”。

我相信正在发生的事情是民意调查是用数字/整数创建的,而 Telerik 很聪明,将它们视为整数而不是字符串。

有没有办法告诉 Telerik RadChart 将所有内容视为字符串或基于每个条目格式化内容。

这两个人遇到了类似的问题;

http://www.telerik.com/community/forums/aspnet-ajax/chart/x-axis-values-mixed-strings-and-ints.aspx

http://www.telerik.com/community/forums/wpf/chart/error-binding-string-value-to-x-axis-using-mvvm.aspx

CS

private void PopulatePollResults(int pollID)
    {
        SqlHelper sql = new SqlHelper();
        DataSet dsResults = sql.ExecuteDataSet("ReturnPollResults", pollID);

        dsResults.Tables[0].DefaultView.Sort = "AnswerID DESC";

        trcResults.DataSource = dsResults.Tables[0].DefaultView;
        trcResults.DataBind();

        trcResults.PlotArea.Appearance.Dimensions.Margins.Top = 10;
        trcResults.PlotArea.Appearance.Dimensions.Margins.Right = 5;
        trcResults.PlotArea.Appearance.Dimensions.Margins.Bottom = 10;
        trcResults.PlotArea.Appearance.Dimensions.Margins.Left = 177;


        lblNoOfVotes.Text = dsResults.Tables[1].Rows[0]["Count"].ToString() + " vote(s)";
    }

ascx

<telerik:RadChart ID="trcResults" runat="server"
        ChartTitle-Visible="false"
        Legend-Visible="false"
        SeriesOrientation="Horizontal"
        Height="160px"
        Width="240px" >
        <Series>
            <telerik:ChartSeries DataYColumn="Votes"
                DefaultLabelValue="#%">
                <Appearance FillStyle-FillType="Solid" 
                    FillStyle-MainColor="#660066" 
                    Border-Visible="false"
                    TextAppearance-TextProperties-Font="Arial" >
                    <FillStyle FillType="Solid" MainColor="102, 0, 102">
                    </FillStyle>
                    <TextAppearance TextProperties-Font="Arial, 9pt">
                    </TextAppearance>
                    <Border Visible="False" />
                </Appearance>
            </telerik:ChartSeries>
        </Series>
        <Appearance Border-Visible="False" FillStyle-FillType="Solid" 
            FillStyle-MainColor="Transparent" Dimensions-AutoSize="false" 
            Dimensions-Width="220px" Dimensions-Height="160px" >
            <FillStyle MainColor="Transparent">
            </FillStyle>
            <Border Visible="False" />
        </Appearance>
        <PlotArea>
            <YAxis2>
                <AxisLabel>
                    <Appearance RotationAngle="0">
                    </Appearance>
                </AxisLabel>
            </YAxis2>
            <Appearance FillStyle-FillType="Solid" FillStyle-MainColor="Transparent" 
                Border-Visible="False" >
                <FillStyle FillType="Solid" MainColor="Transparent">
                </FillStyle>
                <Border Visible="False" />
            </Appearance>
            <XAxis DataLabelsColumn="AnswerText" IsZeroBased="False">
                <Appearance MajorTick-Color="#333333"
                    TextAppearance-TextProperties-Color="#333333"
                    TextAppearance-TextProperties-Font="Arial" >
                    <TextAppearance TextProperties-Color="51, 51, 51" 
                        TextProperties-Font="Arial, 8pt">
                    </TextAppearance>
                </Appearance>
                <AxisLabel>
                    <Appearance RotationAngle="270">
                    </Appearance>
                </AxisLabel>
                <Items>
                    <telerik:ChartAxisItem>
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="1">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="2">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="3">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="4">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="5">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="6">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                    <telerik:ChartAxisItem Value="7">
                        <TextBlock>
                            <Appearance TextProperties-Font="Arial, 8.25pt">
                            </Appearance>
                        </TextBlock>
                    </telerik:ChartAxisItem>
                </Items>
            </XAxis>
            <YAxis>
                <Appearance Visible="false" />
                <AxisLabel>
                    <Appearance RotationAngle="0">
                    </Appearance>
                </AxisLabel>
            </YAxis>
        </PlotArea>
        <ChartTitle Visible="False">
            <Appearance Visible="False">
            </Appearance>
        </ChartTitle>
        <Legend Visible="False">
            <Appearance Visible="False">
            </Appearance>
        </Legend>
    </telerik:RadChart>

谢谢,

4

1 回答 1

0

http://www.telerik.com/community/forums/aspnet-ajax/chart/input-string-was-not-in-a-correct-format.aspx#2074677

Telerik support proposed the following solution.

...attach handlers to DataBinding and BeforeLayout events and in the first prepend a sentinel symbol to all values and in the second remove the sentinel symbol

 ...
 this.trcResults.DataBinding += this.trcResults_DataBinding;
 this.trcResults.BeforeLayout += this.trcResults_BeforeLayout;
 this.trcResults.DataSource = pcl;
 this.trcResults.DataBind();
}

void trcResults_DataBinding(object sender, EventArgs e)
{
 var senderChart = (RadChart)sender;
 var pcl = senderChart.DataSource as IEnumerable<PollContainer>;

 foreach (var pollContainer in pcl)
 {
  // prepend a sentinel symbol
  pollContainer.AnswerText = "x" + pollContainer.AnswerText;
 }
}


void trcResults_BeforeLayout(object sender, EventArgs e)
{
 foreach (var axisItem in this.trcResults.PlotArea.XAxis.Items)
 {
  // remove the sentinel symbol
  axisItem.TextBlock.Text = axisItem.TextBlock.Text.Remove(0, 1);
 }
}
于 2012-04-24T13:27:16.933 回答