Dear Aspose,
Do you have a sample code for drawing multiple lines on one scatter plot chart?
Best Regards
John
Dear Aspose,
Do you have a sample code for drawing multiple lines on one scatter plot chart?
Best Regards
John
Hi John,
Hi,
Sorry, I guess I didn't make it clear. Actually I am trying to draw 2 X Y scatter lines on one chart. I am wondering how this can be done using getXValues() and getYValues() mehtod.
John
Hi John,
I have percieved your requirement of adding multiple lines in scatter chart and have generated the following sample code for your convenience. Please try using the following sample and share with us if there is any further help needed in this regard.
public static void TestChartWork()
{
PresentationEx pres = new PresentationEx();
SlideEx sld = pres.getSlides().get_Item(0);
//ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ScatterWithMarkers, 20, 20, 700-20, 500-20);
//ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ClusteredColumn, 20, 20, 700-20, 500-20);
ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ScatterWithSmoothLinesAndMarkers, 20, 20, 700-20, 500-20);
// chart.setStyle(StyleTypeEx.Style30);
// chart.setStyle(StyleTypeEx.Style38);
// chart.getChartFormat().getEffect3D().
chart.getChartData().getSeries().clear();
chart.getChartData().getCategories().clear();
chart.getChartData().getChartDataWorkbook().clear(0);
chart.getChartData().getChartDataWorkbook().clear(1);
chart.getChartData().getChartDataWorkbook().clear(2);
int defaultWorksheetIndex = 0;
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory();
String titles [] = new String[]{“s1”,“s2”};
String CatTitles [] = new String[]{“c1”,“c2”,“c3”,“c4”};
double values[][]=new double[4][2];
values[0]=new double[]{10,15};
values[1]=new double[]{20,25};
values[2]=new double[]{30,35};
values[3]=new double[]{40,45};
int colNum = values.length;
//Adding categories
//for(int i=0;i<4;i++)
// chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, i+1,0, CatTitles[i]));
//Adding Series
for(int i=0;i<2;i++)
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, i+2, titles[i]), chart.getType());
//Populating first series
int SeriesIndex=0;
ChartSeriesEx series = null;
series = chart.getChartData().getSeries().get_Item(SeriesIndex);
ArrayList colors = new ArrayList();
for(int i=0;i<2;i++)
{
for(int r=0;r<colNum;r++)
{
double [] value = values[r];
if(i==0)
series.getXValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1+(2SeriesIndex), value[i]));
// series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
else
// series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
series.getYValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1+(2SeriesIndex), value[i]));
}
}
//Populating second series
values[0]=new double[]{5,10};
values[1]=new double[]{2,23};
values[2]=new double[]{67,34};
values[3]=new double[]{73,53};
SeriesIndex=1;
series = null;
series = chart.getChartData().getSeries().get_Item(SeriesIndex);
colors = new ArrayList();
for(int i=0;i<2;i++)
{
for(int r=0;r<colNum;r++)
{
double [] value = values[r];
if(i==0)
series.getXValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1+(2SeriesIndex), value[i]));
// series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
else
// series.getValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1, value[i]));
series.getYValues().add(fact.getCell(defaultWorksheetIndex, r+1, i+1+(2SeriesIndex), value[i]));
}
}
// Save presentation with chart
pres.write(“D:\Aspose Data\m111.pptx”);
}