我正在尝试做一些简单明了的事情。我希望Excel折线图中的图例具有自定义名称。我正在C#(互操作)中创建图表。我的票价是:
Excel.Range xvalues = myWorkSheet.Range["R3", "R5"];
Excel.Range values1 = myWorkSheet.Range["S3", "S5"];
Excel.Range values2 = myWorkSheet.Range["T3", "T5"];
Excel.Range values3 = myWorkSheet.Range["U3", "U5"];
Excel.Range values4 = myWorkSheet.Range["V3", "V5"];
Excel.SeriesCollection sc = myChart.SeriesCollection();
myChart.ChartType = Excel.XlChartType.xlLine;
Excel.Series series1 = sc.NewSeries();
Excel.Series series2 = sc.NewSeries();
Excel.Series series3 = sc.NewSeries();
Excel.Series series4 = sc.NewSeries();
series1.XValues = xValues;
series1.Values = values1;
series1.Name = "mySeries1";
series2.XValues = xValues;
series2.Values = values2;
series2.Name = "mySeries2";
series3.XValues = xValues;
series3.Values = values3;
series3.Name = "mySeries3";
series4.XValues = xValues;
series4.Values = values4;
series4.Name = "mySeries4";
该图表显示良好,并且在我需要的位置显示了图例,但是系列名称未与图例中的线条颜色一起出现。有任何想法吗。
答案 0 :(得分:0)
我未在代码中添加的内容是,我将图例放置在图表区域内。我已经设置了myChart.Legend.Height,myChart.Legend.Left和myChart.Legend.Top属性。我认为我不需要设置Legend.Width属性,因为我认为图例会自动将其设置为适当的宽度。我错了。设置myChart.Legend.Width属性后,就会显示系列名称。