Línea de Tendencia

Agregar Línea de Tendencia

Aspose.Slides para C++ proporciona una API simple para gestionar diferentes Líneas de Tendencia en gráficos:

  1. Cree una instancia de la Presentation clase.
  2. Obtenga la referencia de una diapositiva por su índice.
  3. Agregue un gráfico con datos predeterminados junto con cualquier tipo deseado (este ejemplo utiliza ChartType.ClusteredColumn).
  4. Agregando la línea de tendencia exponencial para la serie de gráficos 1.
  5. Agregando una línea de tendencia lineal para la serie de gráficos 1.
  6. Agregando una línea de tendencia logarítmica para la serie de gráficos 2.
  7. Agregando una línea de tendencia de media móvil para la serie de gráficos 2.
  8. Agregando una línea de tendencia polinómica para la serie de gráficos 3.
  9. Agregando una línea de tendencia de potencia para la serie de gráficos 3.
  10. Escriba la presentación modificada en un archivo PPTX.

El siguiente código se utiliza para crear un gráfico con Líneas de Tendencia.

For complete examples and data files, please go to https://github.com/aspose-slides/Aspose.Slides-for-C
// The path to the documents directory.
const String outPath = u"../out/ChartTrendLines_out.pptx";
//Instantiate Presentation class that represents PPTX file
SharedPtr<Presentation> pres = MakeObject<Presentation>();
//Access first slide
SharedPtr<ISlide> slide = pres->get_Slides()->idx_get(0);
// Add chart with default data
SharedPtr<IChart> chart = slide->get_Shapes()->AddChart(Aspose::Slides::Charts::ChartType::ClusteredColumn, 0, 0, 500, 500);
// Adding ponential trend line for chart series 1
SharedPtr<ITrendline> tredLinep = chart->get_ChartData()->get_Series()->idx_get(0)->get_TrendLines()->Add(Aspose::Slides::Charts::TrendlineType::Exponential);
tredLinep->set_DisplayEquation (false);
tredLinep->set_DisplayRSquaredValue( false);
// Adding Linear trend line for chart series 1
SharedPtr<ITrendline> tredLineLin = chart->get_ChartData()->get_Series()->idx_get(0)->get_TrendLines()->Add(Aspose::Slides::Charts::TrendlineType::Linear);
tredLineLin->set_TrendlineType(TrendlineType::Linear);
tredLineLin->get_Format()->get_Line()->get_FillFormat()->set_FillType(FillType::Solid);
tredLineLin->get_Format()->get_Line()->get_FillFormat()->get_SolidFillColor()->set_Color(System::Drawing::Color::get_Red());
// Adding Logarithmic trend line for chart series 2
SharedPtr<ITrendline> tredLineLog = chart->get_ChartData()->get_Series()->idx_get(1)->get_TrendLines()->Add(Aspose::Slides::Charts::TrendlineType::Logarithmic);
tredLineLog->set_TrendlineType(TrendlineType::Logarithmic);
tredLineLog->AddTextFrameForOverriding(u"New log trend line");
// Adding MovingAverage trend line for chart series 2
SharedPtr<ITrendline> tredLineMovAvg = chart->get_ChartData()->get_Series()->idx_get(1)->get_TrendLines()->Add(Aspose::Slides::Charts::TrendlineType::MovingAverage);
tredLineMovAvg->set_TrendlineType(TrendlineType::MovingAverage);
tredLineMovAvg->set_Period(3);
tredLineMovAvg->set_TrendlineName(u"New TrendLine Name");
// Adding Polynomial trend line for chart series 3
SharedPtr<ITrendline> tredLinePol = chart->get_ChartData()->get_Series()->idx_get(2)->get_TrendLines()->Add(Aspose::Slides::Charts::TrendlineType::Polynomial);
tredLinePol->set_TrendlineType(TrendlineType::Polynomial);
tredLinePol->set_Forward (1);
tredLinePol->set_Order (3);
// Adding Power trend line for chart series 3
SharedPtr<ITrendline> tredLinePower = chart->get_ChartData()->get_Series()->idx_get(1)->get_TrendLines()->Add(Aspose::Slides::Charts::TrendlineType::Power);
tredLinePower->set_TrendlineType( TrendlineType::Power);
tredLinePower->set_Backward( 1);
// Write the presentation file to disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);

Agregar Línea Personalizada

Aspose.Slides para C++ proporciona una API simple para agregar líneas personalizadas en un gráfico. Para agregar una línea simple a una diapositiva seleccionada de la presentación, siga los pasos a continuación:

  • Cree una instancia de la clase Presentation
  • Obtenga la referencia de una diapositiva usando su índice
  • Cree un nuevo gráfico utilizando el método AddChart expuesto por el objeto Shapes
  • Agregue una AutoShape de tipo Línea usando el método AddAutoShape expuesto por el objeto Shapes
  • Establezca el color de las líneas de la forma.
  • Escriba la presentación modificada como un archivo PPTX

El siguiente código se utiliza para crear un gráfico con Líneas Personalizadas.

// The path to the documents directory.
const String outPath = u"../out/AddCustomLines.pptx";
// Load the desired the presentation
SharedPtr<Presentation> pres = MakeObject<Presentation>();
SharedPtr<IChart> chart = pres->get_Slides()->idx_get(0)->get_Shapes()->AddChart(ChartType::ClusteredColumn, 100, 100, 500, 400);
SharedPtr<IAutoShape> shape = chart->get_UserShapes()->get_Shapes()->AddAutoShape(ShapeType::Line, 0, chart->get_Height() / 2, chart->get_Width(), 0);
shape->get_LineFormat()->get_FillFormat()->set_FillType(FillType::Solid);
shape->get_LineFormat()->get_FillFormat()->get_SolidFillColor()->set_Color(Color::get_Red());
//Write the PPTX to Disk
pres->Save(outPath, Aspose::Slides::Export::SaveFormat::Pptx);