⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tu.cpp

📁 非常好用的背包演示系统
💻 CPP
字号:
// tu.cpp : implementation file
//

#include "stdafx.h"
#include "knap1.h"
#include "tu.h"

#include "VcPlot.h"
#include "VcAxis.h"
#include "VcValueScale.h"
#include "VcSeriesCollection.h"
#include "VcSeries.h"
#include "VcPen.h"
#include "VcCategoryScale.h"
#include "VcColor.h"
#include "VcDataGrid.h"
#include "VcBackdrop.h"
#include "VcFill.h"
#include "VcBrush.h"
#include "VcDataPoints.h"
#include "VcDataPoint.h"
#include "VcDataPointLabel.h"
#include "VcAxisTitle.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// tu dialog


tu::tu(CWnd* pParent /*=NULL*/)
	: CDialog(tu::IDD, pParent)
{
	//{{AFX_DATA_INIT(tu)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void tu::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(tu)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(tu, CDialog)
	//{{AFX_MSG_MAP(tu)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// tu message handlers

BOOL tu::OnInitDialog() 
{
	CDialog::OnInitDialog();
	CRect rc;
	GetClientRect(&rc);
	if(!m_Chart.Create("mschart", WS_CHILD| WS_VISIBLE, rc, this, 10))
		return -1;
	
	InitChart();
	DrawChart();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
extern float  v[1000];
extern int    w[1000];
extern int    x[1000];
extern int    m_Num;
void tu::DrawChart()
{
	int nRowCount = m_Num;
 	m_Chart.SetRowCount(nRowCount);
	VARIANT var;
	m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetAuto(FALSE);			// 不自动标注X轴刻度
	m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerLabel(1);// 每刻度一个标注
	m_Chart.GetPlot().GetAxis(0,var).GetCategoryScale().SetDivisionsPerTick(1); // 每刻度一个刻度线//
	m_Chart.GetPlot().GetAxis(0,var).GetAxisTitle().SetText("物品种类");			// X轴名称
	char buf[32];
	srand( (unsigned)time( NULL ) );
	for(int row = 1; row <= nRowCount; row++)
	{
		m_Chart.SetRow(row);
		
		if(x[row]==1)
		{
		    sprintf(buf,"已选物品%d,重量%d", row,w[row]);
	    	m_Chart.SetRowLabel((LPCTSTR)buf);
		    m_Chart.GetDataGrid().SetData(row, 1, v[row], 0);
		}
		else
		{
			sprintf(buf,"未选物品%d,重量%d", row,w[row]);
	    	m_Chart.SetRowLabel((LPCTSTR)buf);
		    m_Chart.GetDataGrid().SetData(row, 1, v[row], 0);
		}
	}
	m_Chart.Refresh();	

}
 
void tu::InitChart()
{	// 设置标题
	m_Chart.SetTitleText("0-1背包问题算法物品数据显示 ");
	// 下面两句改变背景色
	m_Chart.GetBackdrop().GetFill().SetStyle(1);
	m_Chart.GetBackdrop().GetFill().GetBrush().GetFillColor().Set(221, 221, 221);
	// 显示图例
	m_Chart.SetShowLegend(TRUE);
	m_Chart.SetColumn(1);
	m_Chart.SetColumnLabel((LPCTSTR)"物品");
 	// 栈模式
	m_Chart.SetStacking(FALSE);
	// Y轴设置
	VARIANT var;
	m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetAuto(FALSE);	// 不自动标注Y轴刻度
	m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMaximum(100);	// Y轴最大刻度
	m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinimum(0);		// Y轴最小刻度
	m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMajorDivision(100);	// Y轴刻度5等分
	m_Chart.GetPlot().GetAxis(1,var).GetValueScale().SetMinorDivision(1);	// 每刻度一个刻度线
	m_Chart.GetPlot().GetAxis(1,var).GetAxisTitle().SetText("物品价值");	// Y轴名称
	// 1条曲线
	m_Chart.SetColumnCount(1); 
	// 线色
	//m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().GetVtColor().Set(0, 0, 255);
 	// 数据点类型显示数据值的模式(对柱柱状图和点线图有效)
	// 0: 不显示	1: 显示在柱状图外
	// 2: 显示在柱状图内上方	3: 显示在柱状图内中间	4: 显示在柱状图内下方
	m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -