1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    TestLinePlot.cxx
5 
6   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7   All rights reserved.
8   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10      This software is distributed WITHOUT ANY WARRANTY; without even
11      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12      PURPOSE.  See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
16 #include "vtkRenderer.h"
17 #include "vtkRenderWindow.h"
18 #include "vtkSmartPointer.h"
19 #include "vtkChartPie.h"
20 #include "vtkPlot.h"
21 #include "vtkPlotPie.h"
22 #include "vtkTable.h"
23 #include "vtkIntArray.h"
24 #include "vtkStringArray.h"
25 #include "vtkContextView.h"
26 #include "vtkContextScene.h"
27 #include "vtkRenderWindowInteractor.h"
28 #include "vtkNew.h"
29 #include "vtkColorSeries.h"
30 
31 #define NUM_ITEMS (5)
32 static int data[] = {77938,9109,2070,12806,19514};
33 //static int data[] = {200,200,200,200,200};
34 static const char *labels[] = {"Books","New and Popular","Periodical","Audiobook","Video"};
35 
36 //----------------------------------------------------------------------------
TestPieChart(int,char * [])37 int TestPieChart(int , char * [])
38 {
39   // Set up a 2D scene, add an XY chart to it
40   vtkNew<vtkContextView> view;
41   view->GetRenderer()->SetBackground(1.0, 1.0, 1.0);
42   view->GetRenderWindow()->SetSize(600, 350);
43   vtkNew<vtkChartPie> chart;
44   view->GetScene()->AddItem(chart.GetPointer());
45 
46   // Create a table with some points in it...
47   vtkNew<vtkTable> table;
48 
49   vtkNew<vtkIntArray> arrData;
50   vtkNew<vtkStringArray> labelArray;
51 
52   arrData->SetName("2008 Circulation");
53   for (int i = 0; i < NUM_ITEMS; i++)
54     {
55     arrData->InsertNextValue(data[i]);
56     labelArray->InsertNextValue(labels[i]);
57     }
58 
59   table->AddColumn(arrData.GetPointer());
60 
61   // Create a color series to use with our stacks.
62   vtkNew<vtkColorSeries> colorSeries;
63   colorSeries->SetColorScheme(vtkColorSeries::WARM);
64 
65   // Add multiple line plots, setting the colors etc
66   vtkPlotPie *pie = vtkPlotPie::SafeDownCast(chart->AddPlot(0));
67   pie->SetColorSeries(colorSeries.GetPointer());
68   pie->SetInputData(table.GetPointer());
69   pie->SetInputArray(0, "2008 Circulation");
70   pie->SetLabels(labelArray.GetPointer());
71 
72   chart->SetShowLegend(true);
73 
74   chart->SetTitle("Circulation 2008");
75 
76   //Finally render the scene and compare the image to a reference image
77   view->GetRenderWindow()->SetMultiSamples(0);
78   view->GetInteractor()->Initialize();
79   view->GetInteractor()->Start();
80 
81   return EXIT_SUCCESS;
82 }
83