Aspose Slides Default YValue

Hi,

I am exporting data to create a chart in powerpoint, I want a bar chart where the bars are all the same height regardless of their YValue, however, I want to display the YValue as the data label? For example, for a bar chart with three elements in and YValues of 50,70,80 - then I would want the height of them all to be 100 but the data labels to say 50, 70 & 80.

Is this possible?

Thanks in advance.

@jack.putt,

I have observed your requirements and like to share that the height of bar in a chart is dependent on data point value for the respective chart series element. If all chart series data elements values are same then all chart bars will have same height. I hope the shared information will be helpful.

Is there a way to assign a name to the data point as well as a value (along the lines of a KeyValuePair)?

@jack.putt,

Can you please share the requirements in the form of sample presentations and I will check in API if that can be achieved using Aspose.Slides.

using(Presentation pres = new Presentation(filePathToPPT))
{
    ISlide slide = pres.Slides[0];
    IShape ch = FindShapeByName(slide, "chartPlaceholderName"); //finds the chart on the slide
    
    IChart chart = (IChart)ch;
    IChartDataWorkbook fact =  chart.ChartData.ChartDataWorkbook;
    chart.ChartData.Series.Clear();
    chart.ChartData.Categories.Clear();
    int s = chart.ChartData.Series.Count;
    s = chart.ChartData.Categories.Count;
   int seriesCount = 1, elementCount = 1;
   List<string> seriesNames = new List<string>();
   List<string> yValues = new List<string>();

   seriesNames.Add("N1");
   yValue.Add("35");
   seriesNames.Add("N2");
   yValue.Add("60");

   for(int i=0; i<seriesNames.Count; i++)
   {
         chart.ChartDataSeries.Add(fact.GetCell(index, 0, seriesCounter, seriesNames[i], chart.Type);
         seriesCount++;
   }
   
  for (int j = 0; j < seriesCounter - 1; j++)
  {
         IChartSeries series = chart.ChartData.Series[j];
         series.DataPoints.AddDataPointForBarSeries(fact.GetCell(index, 0, j + 1, 100)); //Set to default 100
         series.Labels.DefaultDataLabelFormat.ShowValue = true;
         series.Labels.DefaultDataLabelFormat.IsNumberFormatLinkedToSource = true;
         series.Labels.Text = yValue[j]; //This is what I want to do 
  }

pres.Save(saveFileAs, SaveFormat.Pptx);
}

That is what I want the code to do but I’m not aware of anyway to assign my own value to a label that isnt the datavalue.

Many thanks.

@jack.putt,

I have observed the sample code shared by you and have found that you are using source presentation in your code. Please share the source presentation as well generated and desired output presentation. Please share the information so that I may proceed further with my investigation.

Apologies for the delayed reply. Attached is an example file (it is an ppt file but the upload wizard doesnt allow ppt’s to be uploaded so I have exported it to PDF)

ExampleTemplate.pdf (323.8 KB)

  • Slide 1 shows how the template chart is and Slide 2 shows the desired output.

@jack.putt,

I have observed the bar chart sample in shared PDF from you. I like to clarify one thing to you is that when you add an MSO chart either using PowerPoint or by Aspose.Slides, you the length of bar depends on value of respective chart’s category data element inside chart series. If a chart with same length for bar is desired then you need to set the same data element value for the series. Otherwise, it is not possible even using PowerPoint.