Hi
here i have attached my code of c#. as you can see i m calling the "chartVu.ResetChartObjectList();" at the strat of code and then adding all the required controls. please tell me where i m wrong as with this code i m not been able to use rotate function after reset the chart object first time.
Vikas.
vikas.agarwal@hcl.in
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using com.quinncurtis.chart3dnet;
using System.Data.SqlClient;
namespace HCL.DBLab.Charts
{
public partial class Charts : UserControl
{
/// <summary>
/// Required designer variable to define type of coordinate system choosen for charting.
/// </summary>
CartesianCoordinates pTransform1;
public Charts()
{
// This call is required by the Windows Form Designer.
InitializeComponent();
}
/// <summary>
/// This method actually plots the required chart using the information from server.
/// </summary>
public void InitializeChart(DataTable diagramTable, int diagramDimension, int diagramType)
{
DataView dv0 = new DataView(diagramTable, "DIMENSION = '0'", "DIMENSION", DataViewRowState.CurrentRows);
dv0.Sort = "planno";
DataView dv1 = new DataView(diagramTable, "DIMENSION = '1'", "DIMENSION", DataViewRowState.CurrentRows);
dv1.Sort = "planno";
int planCount = Convert.ToInt32(dv0[dv0.Count - 1][4]);
ChartView chartVu = this.chartView;
chartVu.ResetChartObjectList();
Font theFont = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
int planCounter = 0;
int elementCounter = 0;
int[] planElement = new int[planCount + 1];
for (int counter = 0; counter < dv0.Count; counter++)
{
if (planCounter != (int)dv0[counter][4])
{
planCounter = planCounter + 1;
elementCounter = 0;
}
planElement[planCounter] = elementCounter + 1;
elementCounter++;
}
double[][] x = new double[planCount + 1][];
double[][] y = new double[planCount + 1][];
double[][] z = new double[planCount + 1][];
double[] x1 = new double[1];
double[] y1 = new double[1];
double[] z1 = new double[1];
for (int dataDimension = 0; dataDimension <= planCount; dataDimension++)
{
x[dataDimension] = new double[planElement[dataDimension]];
y[dataDimension] = new double[planElement[dataDimension]];
z[dataDimension] = new double[planElement[dataDimension]];
}
int plCounter = 0;
int elCounter = 0;
for (int dataFeeder = 0; dataFeeder < dv0.Count; dataFeeder++)
{
if (plCounter != (int)dv0[dataFeeder][4])
{
plCounter = plCounter + 1;
elCounter = 0;
}
if ((diagramDimension <= 2) && ((diagramType !=1) && (diagramType != 2)))
{
x[plCounter][elCounter] = Convert.ToDouble(dv0[dataFeeder][5]);
}
else
{
x[plCounter][elCounter] = Convert.ToDouble(dv1[dataFeeder][5]);
}
if (diagramDimension >= 2)
{
if ((diagramType == 1) || (diagramType == 2))
{
y[plCounter][elCounter] = Convert.ToDouble(dv0[dataFeeder][5]);
}
else
{
y[plCounter][elCounter] = Convert.ToDouble(dv0[dataFeeder][6]);
}
}
if (diagramDimension == 3)
{
z[plCounter][elCounter] = Convert.ToDouble(dv0[dataFeeder][5]);
}
elCounter++;
}
pTransform1 = new CartesianCoordinates(ChartObj.LINEAR_SCALE, ChartObj.LINEAR_SCALE);
Color[] color = { Color.Blue, Color.Maroon, Color.Red, Color.Yellow,
Color.AliceBlue,Color.AntiqueWhite,Color.Azure,Color.Black,
Color.Brown,Color.Crimson,Color.Crimson,Color.DarkBlue,
Color.DarkOrange,Color.Gold,Color.Firebrick,Color.GreenYellow,
Color.PaleVioletRed,Color.Pink,Color.Tomato};
SimpleDataset3D[] Dataset = new SimpleDataset3D[planCount + 1];
ChartAttribute[] attrib = new ChartAttribute[planCount + 1];
SimpleScatterPlot[] thePlot = new SimpleScatterPlot[planCount + 1];
SimpleDataset[] datasetarray = new SimpleDataset[planCount + 2];
SimpleDataset3D Dataset4 = new SimpleDataset3D("Fourth", x1, y1, z1);
// Create datasets
for (int dataSetCount = 0; dataSetCount <= planCount; dataSetCount++)
{
string name = "planno." + dataSetCount.ToString();
Dataset[dataSetCount] = new SimpleDataset3D(name, x[dataSetCount], y[dataSetCount], z[dataSetCount]);
datasetarray[dataSetCount] = Dataset[dataSetCount];
}
datasetarray[planCount + 1] = Dataset4;
pTransform1.AutoScale(datasetarray, ChartObj.AUTOAXES_FAR, ChartObj.AUTOAXES_FAR);
for (int dataSetCount = planCount; dataSetCount >= 0; dataSetCount--)
{
attrib[dataSetCount] = new ChartAttribute(color[dataSetCount], 33, DashStyle.Solid, color[dataSetCount]);
attrib[dataSetCount].SetSymbolSize(33);
thePlot[dataSetCount] = new SimpleScatterPlot(pTransform1, Dataset[dataSetCount], ChartObj.CUBE3D, attrib[dataSetCount]);
thePlot[dataSetCount].SetSegmentAttributesMode(false);
chartVu.AddChartObject(thePlot[dataSetCount]);
}
// Position chart in graph area
pTransform1.SetGraphBorderDiagonal(0.2, .25, .650, 0.800);
// Set rotational parameters
pTransform1.AbsRotateCoordinateSystem(new Point3D(0, 0, 0));
// Define chart background
Background background = new Background(pTransform1, ChartObj.GRAPH_BACKGROUND, Color.White);
chartVu.AddChartObject(background);
// Define x-axis
LinearAxis xAxis = new LinearAxis(pTransform1, ChartObj.X_AXIS);
xAxis.SetAxisIntercept(0.0);
chartVu.AddChartObject(xAxis);
// Define y-axis
LinearAxis yAxis = new LinearAxis(pTransform1, ChartObj.Y_AXIS);
// Define x-axis labels
NumericAxisLabels xAxisLab = new NumericAxisLabels(xAxis);
xAxisLab.SetTextFont(theFont);
chartVu.AddChartObject(xAxisLab);
// Define x-axis titles
Font titleFont = new Font("Microsoft Sans Serif", 10, FontStyle.Bold);
AxisTitle xaxistitle = new AxisTitle(xAxis, titleFont, "title2");
chartVu.AddChartObject(xaxistitle);
// Define fourth plot as a scatter plot using 3D data
ChartAttribute attrib4 = new ChartAttribute(Color.Transparent, 3, DashStyle.Dot, Color.Transparent);
attrib4.SetSymbolSize(0);
SimpleScatterPlot thePlot4 = new SimpleScatterPlot(pTransform1, Dataset4, ChartObj.CUBE3D, attrib4);
thePlot4.SetSegmentAttributesMode(false);
chartVu.AddChartObject(thePlot4);
// Define title
Font theTitleFont = new Font("Microsoft Sans Serif", 14, FontStyle.Bold);
ChartTitle mainTitle = new ChartTitle(theTitleFont, "Compilation Cost Diagram");
mainTitle.SetTitleType(ChartObj.CHART_HEADER);
mainTitle.SetTitlePosition(ChartObj.CENTER_GRAPH);
chartVu.AddChartObject(mainTitle);
// Add a line to the top of the graph
GraphicsPath titleLine = new GraphicsPath();
titleLine.AddLine(0.0f, 0.1f, 1.0f, 0.1f);
ChartShape titleLineShape = new ChartShape(titleLine,
ChartObj.NORM_GRAPH_POS, 0.0, 0.0, ChartObj.NORM_GRAPH_POS, 0);
titleLineShape.SetLineWidth(3);
chartVu.AddChartObject(titleLineShape);
// Define a tooltip
Font toolTipFont = new Font("Microsoft Sans Serif", 10, FontStyle.Regular);
DataToolTip datatooltip = new DataToolTip(chartVu);
NumericLabel xValueTemplate = new NumericLabel(ChartObj.DECIMALFORMAT, 0);
ChartText textTemplate = new ChartText(toolTipFont, "");
textTemplate.SetTextBgColor(Color.FromArgb(255, 255, 204));
textTemplate.SetTextBgMode(true);
ChartSymbol toolTipSymbol = new ChartSymbol(null, ChartObj.SQUARE, new ChartAttribute(Color.Green));
toolTipSymbol.SetSymbolSize(10.0);
datatooltip.SetTextTemplate(textTemplate);
datatooltip.SetXValueTemplate(xValueTemplate);
datatooltip.SetDataToolTipFormat(ChartObj.DATA_TOOLTIP_X);
if (diagramDimension >= 2)
{
// Add y-axis
chartVu.AddChartObject(yAxis);
// Define y-axis labels
NumericAxisLabels yAxisLab = new NumericAxisLabels(yAxis);
yAxisLab.SetTextFont(theFont);
chartVu.AddChartObject(yAxisLab);
// Define y-axis titles
AxisTitle yaxistitle = new AxisTitle(yAxis, titleFont, "title1");
chartVu.AddChartObject(yaxistitle);
NumericLabel yValueTemplate = new NumericLabel(ChartObj.DECIMALFORMAT, 1);
datatooltip.SetYValueTemplate(yValueTemplate);
datatooltip.SetDataToolTipFormat(ChartObj.DATA_TOOLTIP_XY_TWOLINE);
}
if (diagramDimension == 3)
{
pTransform1.AbsRotateCoordinateSystem(new Point3D(15, 30, 5));
// Define walls
ChartAttribute wallAttrib = new ChartAttribute(Color.Black, 1, DashStyle.Solid, Color.Snow);
Wall3D xyMinZWall = new Wall3D(pTransform1, ChartObj.XY_MAXZ_PLANE, 0.002, wallAttrib);
chartVu.AddChartObject(xyMinZWall);
Wall3D yzMinXWall = new Wall3D(pTransform1, ChartObj.YZ_MINX_PLANE, 0.002, wallAttrib);
chartVu.AddChartObject(yzMinXWall);
Wall3D xzMinYWall = new Wall3D(pTransform1, ChartObj.XZ_MINY_PLANE, 0.002, wallAttrib);
chartVu.AddChartObject(xzMinYWall);
// Define z-axis
LinearAxis zAxis = new LinearAxis(pTransform1, ChartObj.Z_AXIS);
zAxis.AxisIntercept2 = yAxis.AxisMin;
zAxis.AxisTickSpace = 5;
zAxis.AxisMinorTicksPerMajor = 5;
chartVu.AddChartObject(zAxis);
// Define z-axis labels
NumericAxisLabels zAxisLab = new NumericAxisLabels(zAxis);
zAxisLab.SetTextFont(theFont);
chartVu.AddChartObject(zAxisLab);
// Define z-axis titles
AxisTitle zaxistitle = new AxisTitle(zAxis, titleFont, "title3");
chartVu.AddChartObject(zaxistitle);
NumericLabel zValueTemplate = new NumericLabel(ChartObj.DECIMALFORMAT, 2);
datatooltip.SetYValueTemplate(zValueTemplate);
datatooltip.SetDataToolTipFormat(ChartObj.DATA_TOOLTIP_XYZ_THREELINE);
}
datatooltip.SetToolTipSymbol(toolTipSymbol);
datatooltip.SetEnable(true);
chartVu.AddMouseListener(datatooltip);
// Add a rotate control button to the upper left corner
RotateButtonUserControl rotatebutton = new RotateButtonUserControl(pTransform1);
rotatebutton.Size = new Size(32, 32);
rotatebutton.Location = new Point(8, 8);
chartVu.Controls.Add(rotatebutton);
}
}
}