QT中QChart绘制折线图

目录
  • 一、简单绘图
  • 二、绘制折线图
    • 实例

一、简单绘图

Qt Charts基于Qt的Graphics View架构,其核心组件是QChartViewQChart

  • QChartView是显示图标的视图,基类为QGraphicsView
  • QChart的基类是QGraphicsltem

类的继承关系:

创建项目:.pro文件中添加:QT += charts
代码如下:其他文件未修改,修改代码只在mainwindow.cpp文件中进行。
mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QChartView>
#include <QLineSeries>
#include <QValueAxis>
#include <QtMath>
QT_CHARTS_USE_NAMESPACE

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowTitle("QChart简单绘图");

    //创建图表框架
    QChartView* cview = new QChartView(this);
    QChart* chart = new QChart();
    chart->setTitle("简单函数曲线");

    cview->setChart(chart);
    setCentralWidget(cview);

    //创建折现序列
    QLineSeries* seriesS = new QLineSeries;
    QLineSeries* seriesC = new QLineSeries;
    seriesS->setName("Sinθ");
    seriesC->setName("Cosθ");
    chart->addSeries(seriesS);
    chart->addSeries(seriesC);

    //添加数据绘制
    qreal y0,y1,t=0,intv=0.1;
    size_t count=100;
    for (size_t i=0;i<count;i++) {
        y0 = qSin(t);
        y1 = qCos(t);
        seriesS->append(t,y0);
        seriesC->append(t,y1);
        t += intv;
    }

    //创建坐标轴
    QValueAxis* axisX = new QValueAxis;
    axisX->setRange(0,10);
    chart->setAxisX(axisX,seriesS);
    chart->setAxisX(axisX,seriesC);

    QValueAxis* axisY = new QValueAxis;
    axisY->setRange(-1, 1);
    chart->setAxisY(axisY,seriesS);
    chart->setAxisY(axisY,seriesC);

}

MainWindow::~MainWindow()
{
    delete ui;
}

二、绘制折线图

数据序列类继承关系

坐标类继承关系

实例

初步UI设计

自定义DialogPen类

新建DialogPen类继承QDialog

#ifndef DIALOGPEN_H
#define DIALOGPEN_H

#include <QDialog>
#include <QColorDialog>
#include <QPen>
#include <QPalette>

namespace Ui {
class DialogPen;
}

class DialogPen : public QDialog
{
    Q_OBJECT

public:
    explicit DialogPen(QWidget *parent = nullptr);
    ~DialogPen();

    QPen getpen();
    static QPen getPen(QPen initPen, bool &ok);
    void setPen(const QPen &pen);

private slots:
    void on_pushButton_clicked();

private:
    QPen m_pen;
    Ui::DialogPen *ui;
};

#endif // DIALOGPEN_H
#include "dialogpen.h"
#include "ui_dialogpen.h"
#include <QString>

DialogPen::DialogPen(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::DialogPen)
{
    ui->setupUi(this);
    ui->comboBox->clear();
    ui->comboBox->addItem("NoPen",0);
    ui->comboBox->addItem("SolidLine",1);
    ui->comboBox->addItem("DashLine",2);
    ui->comboBox->addItem("DotLine",3);
    ui->comboBox->addItem("DashDotLine",4);
    ui->comboBox->addItem("DashDotDotLine",5);
    ui->comboBox->addItem("CustomDashLine",6);
    ui->comboBox->setCurrentIndex(0);
}

DialogPen::~DialogPen()
{
    delete ui;
}

void DialogPen::on_pushButton_clicked()
{
    QColor color = m_pen.color();
    QColorDialog::getColor(color);
    if(color.isValid()){
        QString str = QString::asprintf("background-color: rgb(%d,%d,%d)",color.red(),color.green(),color.blue());
        ui->btnColor->setStyleSheet(str);
    }

}

QPen DialogPen::getpen()
{
    m_pen.setStyle(Qt::PenStyle(ui->comboBox->currentIndex()));
    m_pen.setWidth(ui->spinBox->value());
    QColor color = ui->btnColor->palette().color(QPalette::Button);
    m_pen.setColor(color);
    return m_pen;
}

QPen DialogPen::getPen(QPen initPen, bool &ok)
{
    DialogPen* dlg = new DialogPen;
    QPen pen;
    dlg->setPen(initPen);
    int ret = dlg->exec();
    if (ret == QDialog::Accepted){
        pen = dlg->getpen();
        ok = true;
    }else {
        pen = initPen;
        ok = false;
    }
    delete dlg;
    return pen;
}

void DialogPen::setPen(const QPen &pen)
{
    m_pen = pen;
    ui->spinBox->setValue(pen.width());
    int i = static_cast<int>(pen.style());
    ui->comboBox->setCurrentIndex(i);
    ui->btnColor->setAutoFillBackground(true);
    QColor color = pen.color();
    QString str = QString::asprintf("background-color: rgb(%d,%d,%d)",color.red(),color.green(),color.blue());
    ui->btnColor->setStyleSheet(str);
}

mainwindow类

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QChartView>
#include <QtCharts>
#include <QColor>
#include <QLineSeries>
#include <QValueAxis>
#include <QtMath>
#include <QTime>
#include <QChart>
#include <QFontDialog>
#include "dialogpen.h"

QT_CHARTS_USE_NAMESPACE

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:
    void on_actZoomOut_triggered();

    void on_actZoomIn_triggered();

    void on_actReset_triggered();

    void on_actFlush_triggered();

    void on_btn_set_clicked();

    void on_btn_titleFont_clicked();

    void on_rBtn_Up_clicked();

    void on_rBtn_Down_clicked();

    void on_rBtn_Left_clicked();

    void on_rBtn_Right_clicked();

    void on_checkBox_legend_clicked(bool checked);

    void on_checkBox_legendBG_clicked(bool checked);

    void on_pBtn_Font_clicked();

    void on_pBtn_legendcolor_clicked();

    void on_pBtn_setMargin_clicked();

    void on_comboBox_motion_currentIndexChanged(int index);

    void on_comboBox_theme_currentIndexChanged(int index);

    void on_sin_curve_clicked();

    void on_cos_curve_clicked();

    void on_pBtn_name_clicked();

    void on_checkBox_curve_clicked(bool checked);

    void on_checkBox_data_clicked(bool checked);

    void on_pBtn_color_clicked();

    void on_pBtn_pen_clicked();

    void on_horizontalSlider_valueChanged(int value);

    void on_checkBox_pointLableVisible_clicked(bool checked);

    void on_pushButton_13_clicked();

    void on_pushButton_12_clicked();

    void on_rBtn_Y_clicked();

    void on_rBtn_XY_clicked();

    void on_rBtn_XAxies_clicked();

    void on_rBtn_YAxies_clicked();

    void on_Axis_isVisible_clicked(bool checked);

    void on_Axis_range_clicked();

    void on_Axis_setTitle_clicked();

    void on_Axis_titleIsVisible_clicked(bool checked);

    void on_pBtn_style_clicked();

    void on_pBtn_Fontcolor_clicked();

    void on_pBtn_setFont_clicked();

    void on_chk_scaleIsVisible_clicked(bool checked);

    void on_chk_gridLineVisible_clicked(bool checked);

    void on_pBtn_Fontcolor_2_clicked();

    void on_pBtn_Fontcolor_3_clicked();

    void on_spinBox_Tickcount_valueChanged(int arg1);

    void on_spinBox_minorTickcount_valueChanged(int arg1);

    void on_chk_TickLineIsVisible_clicked(bool checked);

    void on_pBtn_Fontcolor_5_clicked();

    void on_pBtn_Fontcolor_4_clicked();

    void on_pBtn_Fontcolor_7_clicked();

    void on_pBtn_Fontcolor_6_clicked();

    void on_chk_MinorTickLineIsVisible_clicked(bool checked);

private:
    Ui::MainWindow *ui;
    void createChart();
    QLineSeries* curSeries;
    QValueAxis* curAxis;

    void prepareData();
    void updateFromChart();
};
#endif // MAINWINDOW_H

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "ui_dialogPen.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    createChart();
    prepareData();
    updateFromChart();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_actZoomOut_triggered()
{
    ui->cView->chart()->zoom(0.8);

}

void MainWindow::on_actZoomIn_triggered()
{
    ui->cView->chart()->zoom(1.2);
}

void MainWindow::on_actReset_triggered()
{
    ui->cView->chart()->zoomReset();
}

void MainWindow::createChart()
{
    QChart* chart = new QChart();
    chart->setTitle("simple curve");
    ui->cView->setChart(chart);
    ui->cView->setRenderHint(QPainter::Antialiasing);
    QLineSeries* series0 = new QLineSeries;
    QLineSeries* series1 = new QLineSeries;
    series0->setName("sin");
    series1->setName("cos");
    curSeries = series0;

    QPen pen;
    pen.setStyle(Qt::DotLine);
    pen.setWidth(2);
    series0->setPen(pen);
    pen.setStyle(Qt::SolidLine);
    pen.setColor(Qt::blue);
    series1->setPen(pen);

    chart->addSeries(series0);
    chart->addSeries(series1);

    QValueAxis* axisX = new QValueAxis;
    QValueAxis* axisY = new QValueAxis;
    curAxis = axisX;
    axisX->setRange(0,10);
    axisX->setLabelFormat("%.1f");
    axisX->setTickCount(11);
    axisX->setMinorTickCount(4);
    axisX->setTitleText("time(secs)");

    axisY->setRange(-1.5,1.5);
    axisY->setTickCount(3);
    axisY->setMinorTickCount(4);
    axisY->setTitleText("value");

    chart->setAxisX(axisX,series0);
    chart->setAxisX(axisX,series1);
    chart->setAxisY(axisY,series0);
    chart->setAxisY(axisY,series1);

}

void MainWindow::prepareData()
{
    QLineSeries* series0 = (QLineSeries*)ui->cView->chart()->series().at(0);
    QLineSeries* series1 = (QLineSeries*)ui->cView->chart()->series().at(1);
    int cnt = 100;
    series0->clear();
    series1->clear();
    qsrand(QTime::currentTime().second());
    qreal t=0, y1, y2, inv=0.1;
    qreal rd;
    for (int i=0; i<cnt; i++) {
        rd = (qrand()%10)-5;
        y1 = qSin(t) + rd/50;
        series0->append(t,y1);

        y2 = qCos(t) + rd/50;
        series1->append(t,y2);
        t += inv;
    }
}

void MainWindow::updateFromChart()
{
    QChart* chart = ui->cView->chart();
    ui->lineEdit_title->setText(chart->title());
    QMargins mg = chart->margins();
    ui->spinBox_Down->setValue(mg.bottom());
    ui->spinBox_Left->setValue(mg.left());
    ui->spinBox_Right->setValue(mg.right());
    ui->spinBox_Up->setValue(mg.top());
}

void MainWindow::on_actFlush_triggered()
{
    prepareData();
}

void MainWindow::on_btn_set_clicked()
{
    QChart *chart = ui->cView->chart();
    chart->setTitle(ui->lineEdit_title->text());
}

void MainWindow::on_btn_titleFont_clicked()
{
    QFont font = ui->cView->chart()->titleFont();
    bool ok = false;
    font = QFontDialog::getFont(&ok,font);
    if(ok)
        ui->cView->chart()->setTitleFont(font);
}

void MainWindow::on_rBtn_Up_clicked()
{
    ui->cView->chart()->legend()->setAlignment(Qt::AlignTop);
}

void MainWindow::on_rBtn_Down_clicked()
{
    ui->cView->chart()->legend()->setAlignment(Qt::AlignBottom);
}

void MainWindow::on_rBtn_Left_clicked()
{
    ui->cView->chart()->legend()->setAlignment(Qt::AlignLeft);
}

void MainWindow::on_rBtn_Right_clicked()
{
    ui->cView->chart()->legend()->setAlignment(Qt::AlignRight);
}

void MainWindow::on_checkBox_legend_clicked(bool checked)
{
    ui->cView->chart()->legend()->setVisible(checked);
}

void MainWindow::on_checkBox_legendBG_clicked(bool checked)
{
    ui->cView->chart()->legend()->setBackgroundVisible(checked);
}

void MainWindow::on_pBtn_Font_clicked()
{
    QFont font = ui->cView->chart()->legend()->font();
    bool ok = false;
    font = QFontDialog::getFont(&ok,font);
    if(ok)
        ui->cView->chart()->legend()->setFont(font);
}

void MainWindow::on_pBtn_legendcolor_clicked()
{
    QColor color = ui->cView->chart()->legend()->labelColor();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        ui->cView->chart()->legend()->setLabelColor(color);
}

void MainWindow::on_pBtn_setMargin_clicked()
{
    QMargins mgs;
    mgs.setTop(ui->spinBox_Up->value());
    mgs.setLeft(ui->spinBox_Down->value());
    mgs.setLeft(ui->spinBox_Left->value());
    mgs.setRight(ui->spinBox_Right->value());
    ui->cView->chart()->setMargins(mgs);
}

void MainWindow::on_comboBox_motion_currentIndexChanged(int index)
{
    ui->cView->chart()->setAnimationOptions((QChart::AnimationOption)index);
}

void MainWindow::on_comboBox_theme_currentIndexChanged(int index)
{
    ui->cView->chart()->setTheme((QChart::ChartTheme)index);
}

void MainWindow::on_sin_curve_clicked()
{
    if(ui->sin_curve->isChecked())
        curSeries = (QLineSeries*)ui->cView->chart()->series().at(0);
    else
        curSeries = (QLineSeries*)ui->cView->chart()->series().at(1);

    //获取curSeries的值, 设置(标题名称,序列可见的,点数据可见,透明度滑动条)
    ui->lineEdit_title->setText(curSeries->name());
    ui->checkBox_curve->setChecked(curSeries->isVisible());
    ui->checkBox_data->setChecked(curSeries->pointsVisible());
    ui->horizontalSlider->setValue(curSeries->opacity()*10);
    ui->checkBox_pointLableVisible->setChecked(curSeries->pointLabelsVisible());
}

void MainWindow::on_cos_curve_clicked()
{
    on_sin_curve_clicked();
}

void MainWindow::on_pBtn_name_clicked()
{
    curSeries->setName(ui->line_name->text());
}

void MainWindow::on_checkBox_curve_clicked(bool checked)
{
    Q_UNUSED(checked)
    curSeries->setVisible(ui->checkBox_curve->isChecked());
}

void MainWindow::on_checkBox_data_clicked(bool checked)
{
    Q_UNUSED(checked)
    curSeries->setPointsVisible(ui->checkBox_data->isChecked());
}

void MainWindow::on_pBtn_color_clicked()
{
    QColor color = curSeries->color();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        curSeries->setColor(color);
}

void MainWindow::on_pBtn_pen_clicked()
{
    bool ok = false;
    QPen pen = curSeries->pen();
    pen = DialogPen::getPen(pen, ok);
    if(ok)
        curSeries->setPen(pen);
}

void MainWindow::on_horizontalSlider_valueChanged(int value)
{
    curSeries->setOpacity(value/10.0);
}

void MainWindow::on_checkBox_pointLableVisible_clicked(bool checked)
{
    curSeries->setPointLabelsVisible(checked);
}

void MainWindow::on_pushButton_13_clicked()
{
    QColor color = curSeries->pointLabelsColor();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        curSeries->setPointLabelsColor(color);
}

void MainWindow::on_pushButton_12_clicked()
{
    QFont font = curSeries->pointLabelsFont();
    bool ok = false;
    font = QFontDialog::getFont(&ok, font);
    if(ok)
        curSeries->setPointLabelsFont(font);
}

void MainWindow::on_rBtn_Y_clicked()
{
    if(ui->rBtn_Y->isChecked())
        curSeries->setPointLabelsFormat("@yPoint");
    else
        curSeries->setPointLabelsFormat("(@xPoint,@yPoint)");
}

void MainWindow::on_rBtn_XY_clicked()
{
    on_rBtn_Y_clicked();
}

void MainWindow::on_rBtn_XAxies_clicked()
{
    // 设置坐标轴
    QList<QAbstractAxis*> axes;
    if(ui->rBtn_XAxies->isChecked())
        axes = ui->cView->chart()->axes(Qt::Horizontal);
    else
        axes = ui->cView->chart()->axes(Qt::Vertical);
    curAxis = (QValueAxis*)axes[0];

    //获取坐标轴属性,显示到界面上
    ui->dSBox_minV->setValue(curAxis->min());
    ui->dSBox_maxV->setValue(curAxis->max());

    ui->Axis_title->setText(curAxis->titleText());
    ui->Axis_titleIsVisible->setChecked(curAxis->isTitleVisible());

    ui->lineEdit_style->setText(curAxis->labelFormat());
    ui->chk_scaleIsVisible->setChecked(curAxis->labelsVisible());

    ui->chk_gridLineVisible->setChecked(curAxis->isGridLineVisible());

    ui->spinBox_Tickcount->setValue(curAxis->tickCount());
    ui->chk_TickLineIsVisible->setChecked(curAxis->isLineVisible());

    ui->spinBox_minorTickcount->setValue(curAxis->minorTickCount());
    ui->chk_MinorTickLineIsVisible->setChecked(curAxis->isMinorGridLineVisible());

}

void MainWindow::on_rBtn_YAxies_clicked()
{
    on_rBtn_XAxies_clicked();
}

void MainWindow::on_Axis_isVisible_clicked(bool checked)
{
    curAxis->setVisible(checked);
}

void MainWindow::on_Axis_range_clicked()
{
    curAxis->setRange(ui->dSBox_minV->value(), ui->dSBox_maxV->value());
}

void MainWindow::on_Axis_setTitle_clicked()
{
    curAxis->setTitleText(ui->Axis_title->text());
}

void MainWindow::on_Axis_titleIsVisible_clicked(bool checked)
{
    curAxis->setTitleVisible(checked);
}

void MainWindow::on_pBtn_style_clicked()
{
    curAxis->setLabelFormat(ui->lineEdit_style->text());
}

void MainWindow::on_pBtn_Fontcolor_clicked()
{
    QColor color = curAxis->labelsColor();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        curAxis->setLabelsColor(color);
}

void MainWindow::on_pBtn_setFont_clicked()
{
    QFont font = curAxis->labelsFont();
    bool ok = false;
    font = QFontDialog::getFont(&ok, font);
    if(ok)
        curAxis->setLabelsFont(font);
}

void MainWindow::on_chk_scaleIsVisible_clicked(bool checked)
{
    curAxis->setLineVisible(checked);
}

void MainWindow::on_chk_gridLineVisible_clicked(bool checked)
{
    curAxis->setGridLineVisible(checked);
}

void MainWindow::on_pBtn_Fontcolor_2_clicked()
{
    QColor color = curAxis->gridLineColor();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        curAxis->setGridLineColor(color);
}

void MainWindow::on_pBtn_Fontcolor_3_clicked()
{
    bool ok = false;
    QPen pen = curAxis->gridLinePen();
    pen = DialogPen::getPen(pen, ok);
    if(ok)
        curAxis->setGridLinePen(pen);
}

void MainWindow::on_spinBox_Tickcount_valueChanged(int arg1)
{
    curAxis->setTickCount(arg1);
}

void MainWindow::on_spinBox_minorTickcount_valueChanged(int arg1)
{
    curAxis->setMinorTickCount(arg1);
}

void MainWindow::on_chk_TickLineIsVisible_clicked(bool checked)
{
    curAxis->setLineVisible(checked);
}

void MainWindow::on_pBtn_Fontcolor_5_clicked()
{
    bool ok = false;
    QPen pen = curAxis->linePen();
    pen = DialogPen::getPen(pen, ok);
    if(ok)
        curAxis->setLinePen(pen);
}

void MainWindow::on_pBtn_Fontcolor_4_clicked()
{
    QColor color = curAxis->linePenColor();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        curAxis->setLinePenColor(color);
}

void MainWindow::on_pBtn_Fontcolor_7_clicked()
{
    QColor color = curAxis->minorGridLineColor();
    color = QColorDialog::getColor(color);
    if(color.isValid())
        curAxis->setMinorGridLineColor(color);
}

void MainWindow::on_pBtn_Fontcolor_6_clicked()
{
    bool ok = false;
    QPen pen = curAxis->gridLinePen();
    pen = DialogPen::getPen(pen, ok);
    if(ok)
        curAxis->setGridLinePen(pen);
}

void MainWindow::on_chk_MinorTickLineIsVisible_clicked(bool checked)
{
    curAxis->setMinorGridLineVisible(checked);
}

效果演示

到此这篇关于QT中QChart绘制折线图的文章就介绍到这了,更多相关QChart绘制折线图内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • 使用EVAL处理jqchart jquery 折线图返回数据无效的解决办法

    eval函数可以把一些处理过程序代码进行解析从而达到可以执行的一个状态,查了很多帖子,jqchart插件做折线图时,处理返回数据时全都是eval,但我怎么也弄不出来,后来发现: 1.根本不需要eval处理,直接截取字符串即可(返回值要拼接好): 2.处理好的字符串放进series的data里要加上[]; 下面是代码: html页面<body>标签里面只放了一个<div id="jqChart" style="width: 500px; height: 300

  • QT中QChart绘制折线图

    目录 一.简单绘图 二.绘制折线图 实例 一.简单绘图 Qt Charts基于Qt的Graphics View架构,其核心组件是QChartView 和 QChart QChartView是显示图标的视图,基类为QGraphicsView QChart的基类是QGraphicsltem 类的继承关系: 创建项目:.pro文件中添加:QT += charts代码如下:其他文件未修改,修改代码只在mainwindow.cpp文件中进行.mainwindow.cpp #include "mainwin

  • PHP中使用GD库绘制折线图 折线统计图的绘制方法

    在PHP中,有一些简单的图像函数是可以直接使用的,但大多数要处理的图像,都需要在编译PHP时加上GD库.除了安装GD库之外,在PHP中还可能需要其他的库,这可以根据需要支持哪些图像格式而定.GD库可以在http://www.boutell.com/gd/免费下载,不同的GD版本支持的图像格式不完全一样,最新的GD库版本支持GIF.JPEG.PNG.WBMP.XBM等格式的图像文件,此外还支持一些如FreeType.Type 1等字体库.通过GD库中的函数可以完成各种点.线.几何图形.文本及颜色的

  • Python读取excel文件中的数据,绘制折线图及散点图

    目录 一.导包 二.绘制简单折线 三.pandas操作Excel的行列 四.pandas处理Excel数据成为字典 五.绘制简单折线图 六.绘制简单散点图 一.导包 import pandas as pd import matplotlib.pyplot as plt 二.绘制简单折线 数据:有一个Excel文件lemon.xlsx,有两个表单,表单名分别为:Python 以及student. Python的表单数据如下所示: student的表单数据如下所示:  1.在利用pandas模块进行

  • python使用matplotlib绘制折线图教程

    matplotlib简介 matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并且Gallery页面中有上百幅缩略图,打开之后都有源程序.因此如果你需要绘制某种类型的图,只需要在这个页面中浏览/复制/粘贴一下,基本上都能搞定. 在Linux下比较著名的数据图工具还有gnuplot,这个是免费的,Python有一个包可以调用gnuplot,但是语法比较不

  • jquery.flot.js简单绘制折线图用法示例

    本文实例讲述了jquery.flot.js简单绘制折线图用法.分享给大家供大家参考,具体如下: 1.完整实例代码: <!DOCTYPE html> <html> <head> <meta charset='utf-8'> <title>折线图</title> <!--[if lte IE 8]> <script language="javascript" type="text/javas

  • python使用matplotlib绘制折线图的示例代码

    示例代码如下: #!/usr/bin/python #-*- coding: utf-8 -*- import matplotlib.pyplot as plt # figsize - 图像尺寸(figsize=(10,10)) # facecolor - 背景色(facecolor="blue") # dpi - 分辨率(dpi=72) fig = plt.figure(figsize=(10,10),facecolor="blue") #figsize默认为4,

  • Python利用matplotlib绘制折线图的新手教程

    前言 matplotlib是Python中的一个第三方库.主要用于开发2D图表,以渐进式.交互式的方式实现数据可视化,可以更直观的呈现数据,使数据更具说服力. 一.安装matplotlib pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple 二.matplotlib图像简介 matplotlib的图像分为三层,容器层.辅助显示层和图像层. 1. 容器层主要由Canvas.Figure.Axes组成. Canvas位

  • R语言绘制折线图实例分析

    折线图是通过在它们之间绘制线段来连接一系列点的图. 这些点在它们的坐标(通常是x坐标)值之一中排序. 折线图通常用于识别数据中的趋势. R语言中的plot()函数用于创建折线图. 语法 在R语言中创建折线图的基本语法是 - plot(v,type,col,xlab,ylab) 以下是所使用的参数的描述 - v是包含数值的向量. 类型采用值"p"仅绘制点,"l"仅绘制线和"o"绘制点和线. xlab是x轴的标签. ylab是y轴的标签. main是

  • python 用matplotlib绘制折线图详情

    目录 1. 折线图概述 1.1什么是折线图? 1.2折线图使用场景 1.3绘制折线图步骤 1.4案例展示 2. 折线2D属性 2.1linestyle:折线样式 2.2color:折线颜色 2.3marker:坐标值标记 2.4fillstyle:标记填充方法 2.5linewidth(lw): 直线宽度 3. 坐标管理 3.1坐标轴名字设置 3.2坐标轴刻度设置 3.3坐标轴位置设置 3.4指定坐标值标注 4. 多条折线展示图 5. 图列管理 复习回顾: 众所周知,matplotlib 是一款

  • Android实现绘制折线图APP代码

    目录 一.总体设计 二.具体模块实现 三.效果展示 四.功能展望 总结 一.总体设计 1.寻找规律,公式化的生成坐标系. 2.将生成坐标系的关键参数设置为可自定义,从而可变的可以生成自己想要的坐标系. 3.将需要绘制的点绘制在坐标系中并生成折现图. 二.具体模块实现 1.坐标系的生成: public void chart(){ imageView=(ImageView)findViewById(R.id.image); newb = Bitmap.createBitmap(w, h, Bitma

随机推荐