0

我有以下图表我想使用 C# 设置两件事

  1. 我如何在图表下方设置 x 轴图例而不是在轴下方,因为它与线重叠?
  2. 我设置的工具提示没有像这样“{0} Sentiment - {1} Volume”?

.

  private void FillChart(IEnumerable<EntitySearchResponse> data)
    {
        SentimentChart.ChartTitle.Text = "Sentemants Per day";

        SentimentChart.PlotArea.YAxis.TitleAppearance.Text = "Sentimants %";


        SentimentChart.PlotArea.XAxis.LabelsAppearance.RotationAngle = 90;
        SentimentChart.PlotArea.XAxis.Step = 10;
        SentimentChart.PlotArea.XAxis.Items.Clear();

        foreach (var date in data.Select(x => x.Date).Distinct())
        {
            var axisItem = new AxisItem(date.ToString("ddd dd"));
            SentimentChart.PlotArea.XAxis.Items.Add(axisItem);
        }

        SentimentChart.DataSource = data;

        SentimentChart.PlotArea.Series.Clear();

        foreach (var entityName in data.Select(x => x.EntityName).Distinct())
        {
            var series = new ColumnSeries();
            series.LabelsAppearance.DataFormatString = "{0} items";
            series.TooltipsAppearance.DataFormatString = "{0} {2} items";
            series.Name = entityName;

            var items = data.Where(x => x.EntityName == entityName).ToList();
            foreach (var entitySearchResponse in items)
            {
                var seriesItem = new SeriesItem(entitySearchResponse.Sentiment);
                seriesItem.TooltipValue = string.Format("{0} Sentiment - {1} Volume", entitySearchResponse.Sentiment,
                                                        entitySearchResponse.Volume);
                series.Items.Add(seriesItem);
            }
            SentimentChart.PlotArea.Series.Add(series);
        }

    }

在此处输入图像描述

4

1 回答 1

0

I guess that by x-axis legends you mean the XAxis labels of the chart. If that is so then there is a TextStyle property exposed by the LabelsAppearance element in the XAxis, that lets you set margin/padding to these labels. More information about this property is available here.

Setting this property, however, will diminish the plot area of the chart, in order to fit in with the set charts dimensions. Therefore you need to amend them (the width/height of the chart) as well.

Regarding the appearance of the tooltip, note that you cannot set a tooltip for an individual SeriesItem. The exceptions is the BubbleSeries that expose such ToolTipValue property. What I can suggest you is to use the ClientTemplate functionality of the chart. This functionality, however, requires the chart to be databound. Therefore you can either directly bind the chart to the datasource, or recreate your current logic, so that there is a datasource that can be databound. You can find useful this demos.telerik.com/aspnet-ajax/htmlchart/examples/functionality/clienttemplates/defaultcs.aspx online demo and this www.telerik.com/help/aspnet-ajax/htmlchart-client-templates-for-tooltips-and-labels.html help article related to using ClientTemplates.

于 2013-05-21T15:05:56.953 回答