Make your own free website on Tripod.com
MsChart change backcolor

MsChart change backcolor

//insert your head file

#include "vcplot.h"

#include "vcbackdrop.h"

#include "vcfill.h"

#include "vcbrush.h"

#include "vccolor.h"

#include "VcShadow.h"

 

 

//No color will appear unless you set the style

m_mschart.GetPlot().GetBackdrop().GetFill().SetStyle(1);

//white

m_mschart.GetPlot().GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);

 

Submitted By: HuGaoMing (2003/03/11)

 

---------------------------------------------------------------------------------------------

How to color bar?

i have an mschart control, with one row and several columns.

i want to color a bar with a different color when it exceeds a limit. (i have 1 series only).

 

my question is how i will be able to change the color?

 

i tried the following code but it fails :

 

CVcPlot aplot = m_pChart->GetPlot();

CVcSeriesCollection aSerCol = aplot.GetSeriesCollection();

CVcSeries aSeries = aSerCol.GetItem(1); // i have only 1..

CVcStatLine aStatLine = aSeries.GetStatLine();

CVcColor aColor = aStatLine.GetVtColor();

aColor.Set(120, 120, 120);

 

Submitted By: giorgos (2001/10/30)

-----------------------------------------------------------------------------------------------------------------------

set x-coordinates: (e.g. time) & change values for Y-Axis

I have found out something, maybe it's helpfull for you:

 

....

#include "vcaxis.h"

#include "vcplot.h"

#include "vcvaluescale.h"

....

 

 

// set x-coordinates: e.g. time

int hour = 12;

for(int min = 1 ; min < nr_row+1; min++)

{

m_mschart1.SetRow(min);

CString str;

str.Format("%2d:%02d",hour,min);

m_mschart1.SetRowLabel(str);

}

 

// change values for Y-Axis

 

enum {

VtChAxisIdX = 0,

VtChAxisIdY = 1,

VtChAxisIdY2 = 2,

VtChAxisIdZ = 3,

VtChAxisIdNone = 4

} VtChAxisId;

 

const VARIANT Index;

 

CVcAxis m_axis = m_mschart1.GetPlot().GetAxis(VtChAxisIdY,Index);

double max_scale = 50.0;

double min_scale = 10.0;

CVcValueScale m_scale;

m_scale = m_axis.GetValueScale();

 

short m_YAxis_Division_old = m_scale.GetMajorDivision();

short m_YAxis_Division_new = 5;

m_scale.SetMajorDivision(m_YAxis_Division_new);

 

m_scale.SetAuto(FALSE);

m_scale.SetMaximum(max_scale);

m_scale.SetMinimum(min_scale);

 

Submitted By: Gotthard Petzold (2002/02/19)

------------------------------------------------------------------------------------------------------------------------------------

Hiding Markers

 

I could hide the markers doing like this:

 

 

CVcPlot aplot = m_Chart->GetPlot();

CVcSeriesCollection aSerCol = aplot.GetSeriesCollection();

for (int i=1; i<(m_Chart->GetColumnCount()); i++)

{

            CVcSeries aSeries = aSerCol.GetItem(i);

            CVcSeriesMarker aSerMarker = aSeries.GetSeriesMarker();

            aSerMarker.SetShow(FALSE);

}

 

 

If you want to enable markers just set TRUE in the last instruction.

 

Submitted By: Johan (2002/03/29)

zib78@hotmail.com

-----------------------------------------------------------------------------------------------

FYI, adding x,y titles

 

This worked for me....

 

 

 

Before the refresh add:

 

 

 

CVcPlot plot(m_m_Chart.GetPlot());

_variant_t  Index((long) 0);

 

 

 

// Spruce up title

CVcTitle title(m_m_Chart.GetTitle());

title.SetText(sztitle);

CVcFont font(title.GetVtFont());

font.SetName(_TEXT("Arial"));

font.SetSize(36.0);

font.SetStyle(VtFontStyleBold);

 

 

 

// Label X Axis

CVcAxis xaxis(plot.GetAxis(VtChAxisIdX, Index ));

CVcAxisTitle xaxistitle(xaxis.GetAxisTitle());

xaxistitle.SetVisible(true);

CString Xaxistitle = xaxistitle.GetText();

CString szXaxistitle="Cycles";

xaxistitle.SetText(szXaxistitle);

 

 

 

CVcFont xfont(xaxistitle.GetVtFont());

xfont.SetName(_TEXT("Arial"));

xfont.SetSize(16.0);

xfont.SetStyle(VtFontStyleBold);

 

 

 

// Label Y Axis

CVcAxis yaxis(plot.GetAxis(VtChAxisIdY, Index ));

CVcAxisTitle yaxistitle(yaxis.GetAxisTitle());

yaxistitle.SetVisible(true);

CString szYaxistitle="Position";

yaxistitle.SetText(szYaxistitle);

 

 

 

 

 

Submitted By: jmichaloski (2001/06/07)

John.Michaloski@nist.gov

-----------------------------------------------------------------------------------

How to handle multiline MSCHART Titles

Found the solution, you need to set the Title's TextLayout property" WordWrap to true so that it will understand the \r\n....

 

#include "VcTextLayout.h"

....

CVcTextLayout titlelayout = title.GetTextLayout();

titlelayout.SetWordWrap(true);

 

This worked for me.

 

 

Submitted By: John Michaloski (2002/03/05)

John.Michaloski@nist.gov

-------------------------------------------------------------------------------

 Set Row Labels

// You may try this simple code to change the row labels

 

CString sLabel;

int iRow;

 

m_chart.SetRowLabelCount(1);//defualt value, you may ignore this line

m_chart.SetRowLabelIndex(1);//defualt value, you may ignore this line

 

 

m_chart.SetRowCount(10);//set number of labels you need to add

 

for (iRow = 1; iRow <= 10; iRow++)

{

sLabel.Format ("%d", iRow);

m_chart.SetRow(iRow);//set the index of the label to be modified

m_chart.SetRowLabel(sLabel);// modify it

}

m_chart.Refresh;

 

 

Submitted By: Ahmed (2003/02/21)

asfamin@hotmail.com

-------------------------------------------------------------------------------------

 

 Adding Row/Col Labels

 

....

 

// You need this header for the IDispatch wrapped

// vcdatagrid interface (this file was created when

// (you added the chart control to your project)

 

 

 

#include "vcdatagrid.h"

 

CString sLabel;

int iCol, iRow;

 

 //IVcDataGrid Interface

 CVcDataGrid IDatagrid (m_Chart.GetDataGrid());

 

 // Label the Data

 //Series Names (series data in colums)

  for (iCol = 0; iCol < m_iNumberOfSeries; iCol++)

  {

IDatagrid.SetColumnLabel(iCol+1,1,

            m_strSeriesName[iCol]);

 

}

 

 // Just name row data labels 1....n

  for (iRow = 0; iRow < m_iNumParams; iRow++)

{

sLabel.Format ("%d", iRow+1);

IDatagrid.SetRowLabel(iRow+1,1,sLabel);

 

}

 

Submitted By: Bill Edgar (2001/03/20

bedgar1ct@yahoo.com

-------------------------------------------------------------------------------------

How to plot numbers with decimals

 

Thanks to JL Colson for this sample.

 

 

If you want to plot numbers with decimals you must modify this sample like that :

 

COleSafeArray saRet;

 

// To test

double val=0;

double step=0.5;

 

DWORD numElements[] = {10, 10}; // 10x10

 

// Create the safe-array...

// Change to VT_VARIANT

 

saRet.Create(VT_VARIANT, 2, numElements);

// Initialize it with values...

 

long index[2];

for(index[0]=0; index[0]<10; index[0]++)

{

 for(index[1]=0; index[1]<10; index[1]++)

{

 double val += step;

 // Change to COleVariant

                         saRet.PutElement(index, COleVariant( val ));

             }

}

 

 

 

// Return the safe-array encapsulated in a VARIANT...

m_Chart.SetChartData(saRet.Detach());

 

m_Chart.Refresh();        

 

Submitted By: Chris (2001/03/17)

christophe.erussard@wanadoo.fr

------------------------------------------------------------------------------------------------