Free Support Forum - aspose.com

Percents Stacked Bar help

Hi


I am trying to update this chart with the code below the data is coming form a datatable and this only add data into on row so all other rows are not updates

int count = 0;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
ChartSeriesEx series = chart.ChartData.Series[0];
for (int i = 0; i < extractedData.Rows.Count; i++)
{
string insertedValue = extractedData.Rows[i][valuesUsed[5]].ToString();
if (insertedValue.Equals("-") || insertedValue.Equals(""))
{
insertedValue = “0”;
}

if (i<6)
{
fact.GetCell(0, 0, 1, “Newspapers”);
series.Values[i].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
}
else if (i < 12)
{
fact.GetCell(0, 0, 2, “Magazines”);
series.Values[count].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count++;
}
else if ( i < 18)
{
fact.GetCell(0, 0, 3, “Television”);
series.Values[count1].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count1++;
}
else if ( i < 24)
{
fact.GetCell(0, 0, 4, “Internet”);
series.Values[count2].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count2++;
}
else if ( i < 30)
{
fact.GetCell(0, 0, 5, “Outdoor Media”);
series.Values[count3].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count3++;
}
else if (i < 36)
{
fact.GetCell(0, 0, 6, “Cinema”);
series.Values[count4].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count4++;
}
else if (i >= 36)
{
fact.GetCell(0, 0, 7, “Radio”);
series.Values[count5].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count5++;
}

Hi,


I have observed the presentation file shared by you and have observed the part of code shared by you. Please share the problem statement that what issue you are having while updating the chart and what out put you are yielding. Please also share what out put you are expecting. Please share the complete sample application that I can use on my end to fulfill your requirements. If you are using data form database then you may define some data table in your code and populate it with sample data. Kindly share the sample application with us so that I may help you further.

Many Thanks,

once i update the chart all that is returned i final row of data in different series.


and i would like the chart to be edited like the one in the presentation that i have given

Hi Jim,


I am sorry for your inconvenience. We really like to help you and resolve the issue on your end. But for that I need a working sample code from your end. As I shared in my previous post that your sample code has extractedData and valuesUsed custom data variables. I am unable to use your code snippet. Can you please provide a working sample that I may try on my end to help you further. Also the chart that you have shared is source chart. Can you please share what chart you are getting by using Aspose.Slides and what chart you are expecting as output. Please share the requested information and I will be really keen to help you further.

Many Thanks,

would it be possible for you to just use random data that u make up and show me how to make it work.

Hi Jim,


I have tried to understand the requirements shared by you but regret to share that you have unfortunately not shared the output that you are looking for. However, I have worked with the part of sample code shared by you and have been able to modify the chart as per your logic defined in the code without any issue. For your kind reference, I have shared the modified sample code and generated presentation. However, if there is still an issue then I request you to kindly provide the chart data in the form of DataTable that I have used as well. Please also share the output presentation as well that you are looking for. I will try to help you further.

public static System.Data.DataTable GetBarTable()
{
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add(“BarValue”, typeof(double));
//table.Columns.Add(“NormalValue”, typeof(double));

table.Rows.Add(2);
table.Rows.Add(3);
table.Rows.Add(6);
table.Rows.Add(8);
table.Rows.Add(7);
table.Rows.Add(4);
table.Rows.Add(2);
// table.Rows.Add(1);
// table.Rows.Add(9);
// table.Rows.Add(6);
return table;
}

public static void ModifyBarChart()
{

String path = @“D:\Aspose Data”;
PresentationEx pres = new PresentationEx(path + “Help2.pptx”);
SlideEx slide = pres.Slides[0];
ChartEx chart = (ChartEx)slide.Shapes[0];
ChartDataEx data = chart.ChartData;
System.Data.DataTable extractedData = GetBarTable();

int count = 0;
int count1 = 0;
int count2 = 0;
int count3 = 0;
int count4 = 0;
int count5 = 0;
ChartDataCellFactory fact = chart.ChartData.ChartDataCellFactory;
ChartSeriesEx series = chart.ChartData.Series[0];
for (int i = 0; i < extractedData.Rows.Count; i++)
{
string insertedValue = extractedData.Rows[i][0].ToString();


if (insertedValue.Equals("-") || insertedValue.Equals(""))
{
insertedValue = “0”;
}

if (i < 6)
{
fact.GetCell(0, 0, 1, “Newspapers”);
series.Values[i].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
}
else if (i < 12)
{
fact.GetCell(0, 0, 2, “Magazines”);
series.Values[count].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count++;
}
else if (i < 18)
{
fact.GetCell(0, 0, 3, “Television”);
series.Values[count1].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count1++;
}
else if (i < 24)
{
fact.GetCell(0, 0, 4, “Internet”);
series.Values[count2].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count2++;
}
else if (i < 30)
{
fact.GetCell(0, 0, 5, “Outdoor Media”);
series.Values[count3].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count3++;
}
else if (i < 36)
{
fact.GetCell(0, 0, 6, “Cinema”);
series.Values[count4].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count4++;
}
else if (i >= 36)
{
fact.GetCell(0, 0, 7, “Radio”);
series.Values[count5].Value = Math.Round(Convert.ToDouble(insertedValue), MidpointRounding.AwayFromZero);
count5++;
}
}
pres.Write(path + “ModifiedBarChart.pptx”);
}

Many Thanks,